我期待了好几天。我做了一个休息应用程序。我通过 url 向它发送字符串数据,并从中获取响应 json 数据。当我在浏览器上写入 url 时,我成功地看到了 json 值:
网址:
http://mydomain.com:82/datasnap/rest/TServerMethods1/ReverseString/MEHMET?jsoncallback=?
返回 json : {"result":["TEMHEM"]}
我正在尝试像下面这样获取
$.getJSON( "http://mydomain.com:82/datasnap/rest/TServerMethods1/ReverseString/MEHMET?jsoncallback=?", function( data) {
var dt= JSON.stringify(data);
console.log(dt[0].result);
});
but it give an error :
Uncaught SyntaxError: Unexpected token :
:82/datasnap/rest/TServerMethods1/ReverseString/MEHMET?jsoncallback=jQuery17109582267256919295_1392369668825&_=1392369670613:1
How can I solve this?
Some hints from my side:
You can double check your service with Firefox RestClient Plugin which supports also JSON.
Have a look at the http header for mime type also.
I have tested your code with the service url: http://ip.jsontest.com/ and the request was made without problem.
Another problem can be the console.log command:
Try to change this to something like
console.log(data.result[0]);
或
alert(data.result[0]);
为了调试东西,我使用Firebug(也是一个Firefox插件)。
祝你好运。
马丁