質問

i have 2 web pages containing same JSON string. one work fine with java-script function.but other one is completely not working.the only different between these two is url.

here is the page that is working fine with the js function.

 (http://jsfiddle.net/echo/jsonp/?test=some+html+content&callback=?)

here is the one that is not working with the js function.

 (http://sanjeewa88.byethost31.com/EMPStore/test_json.html)

here is my java-script function

function doJSON() {
 $.getJSON('http://jsfiddle.net/echo/jsonp/?test=some+html+content&callback=?', function (data) {

           $('#allemployees').append("<li>" + data.test+ "</li>");

                   });
                    }

what's wrong with second page and how i fix it to access that page through js function.

PS- i want to display these data in a listview. first one is displaying that remote data on the listview.but second one which having same json string is not displaying anything.

役に立ちましたか?

解決

On the page you provide the json you have to accept a para callback and use this parameter to generate the function name. look what's happen when you call jsfiddle callback with an other name:

http://jsfiddle.net/echo/jsonp/?test=some+html+content&callback=poney

give:

poney({"test": "some html content"});

You have more information here: jQueryDoc

If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top