Skip to content

Commit c6dbcb1

Browse files
达峰xudafeng
达峰
authored andcommitted
fix api
1 parent c335862 commit c6dbcb1

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

assets/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<ul>
2222
<#each val in $list#>
2323
<li>
24-
<button id="button-<#=$val.id#>" data-title="<#=$val.title#>" data-url="<#=$val.url#>"
25-
target="_blank"><#=$val.id#></button>
24+
<button id="<#=$val.id#>" data-title="<#=$val.title#>" data-url="<#=$val.url#>"
25+
target="_blank"><#=$val.index#></button>
2626
<span><#=$val.title#></span>
2727
</li>
2828
<#/each#>

assets/javascript/index.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var exec = function(data, global) {
2626
var html = !!content.innerHTML.length;
2727
var tplElm = $('#template')[0].innerHTML;
2828
var tpl = grace.compile(tplElm);
29-
var API = 'http://xudafeng.com/feedit/read.php';
29+
var API = 'http://xudafeng.com/feedit/api';
3030
var node = tpl({
3131
list: data
3232
});
@@ -39,20 +39,24 @@ var exec = function(data, global) {
3939
document.addEventListener('click', function(e) {
4040
var target = e.target;
4141
if (target.nodeName === 'BUTTON') {
42-
var id = target.id.split('button-')[1];
43-
id = parseInt(id);
42+
var id = target.id;
4443
var url = target.getAttribute('data-url');
4544
var title = target.getAttribute('data-title');
4645
//ajax
4746
JSONP(API, {
48-
id: id
47+
id: id,
48+
type: 'update',
49+
read: 'true',
50+
ua: 'mobile'
4951
}, 'callback', function(data) {
5052
if (data) {
5153
if (data.success) {
5254
target.style.display = 'none';
5355
global.targetTitle = title;
5456
global.targetUrl = url;
5557
location.href = url;
58+
} else {
59+
alert(data.errorMsg);
5660
}
5761
}
5862
});
@@ -61,8 +65,12 @@ var exec = function(data, global) {
6165
}
6266

6367
if (ios) {
64-
this.Ready = function(data) {
65-
exec(data, window);
68+
this.Ready = function(d) {
69+
if (d.success) {
70+
exec(JSON.parse(d.data), window);
71+
} else {
72+
alert('error');
73+
}
6674
};
6775
} else if(android) {
6876
data = dataFromInterface.get('data');

feedit_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

feedit_ios/ViewController.m

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ @implementation ViewController
1818

1919
- (void)viewDidLoad {
2020
[super viewDidLoad];
21-
self.API = @"http://xudafeng.com/feedit";
21+
self.API = @"http://xudafeng.com/feedit/api?type=get&unread=true";
2222
[self setNavButton];
2323
[self loadWebView];
2424
}
@@ -65,15 +65,13 @@ - (void)webViewDidStartLoad:(UIWebView *)webView {
6565
- (void)getData {
6666
NSError *error;
6767
NSURL *url = [NSURL URLWithString: self.API];
68-
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
68+
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval: 10];
6969
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
7070
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
71-
NSDictionary *djson = [json objectForKey:@"data"];
72-
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:djson options:NSJSONWritingPrettyPrinted error:&error];
71+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&error];
7372
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
74-
NSLog(@"jsonobject: %@", jsonString);
75-
NSString *str = @"";
76-
jsonString = [str stringByAppendingFormat:@"Ready(%@)", jsonString];
73+
NSString *str = @"Ready";
74+
jsonString = [str stringByAppendingFormat:@"(%@)", jsonString];
7775
NSLog(@"%@", jsonString);
7876
[self.webView stringByEvaluatingJavaScriptFromString:jsonString];
7977
}

0 commit comments

Comments
 (0)