Replacing the link with PHP is no problem.
$.ajax ({type: ' GET ', Async:false,url: "Http://app.veishu.com/jsonp/categories/all.js", DataType: "Jsonp", Success: function (data) {alert ("Success"),//alert (data[0]),//var datahtml= ""//For (var i=0; data.length;i++) {//datahtml+= "";} $ (". List"). html (datahtml);},error:function () {alert ("Ajax is Error");});
This Ajax does not go into error, nor does it enter success.
In that link JS that error.
If you replace the link with PHP, you will successfully enter success.
But this JS file link directly in the browser open also no problem, can appear json. I don't know what's going on.
There are also browser open JS file has Unicode characters, how to turn!
Reply content:
Using jquery for JSONP calls, the JSON data returned requires a callback name, and because your return value is static data, you should specify the name of the Jsonpcallback.
JQuery (document). Ready (function () { $.ajax ({ type: "Get", async:false, URL: "// app.veishu.com/jsonp/categories/all.js?1.2.1 ", dataType:" Jsonp ", jsonpcallback:" Flighthandler ",// The custom JSONP callback function name success:function (data) { }, error:function () {}}); });
The returned all.js data format is as follows:
Flighthandler ({"Success": TRUE, "data" [{"Name": "\u624b\u5de5diy", "position": 0, "slug": "handicraft"}]});
The principle of JSONP: segmentfault.com/q/1010000002608394/a-1020000002608399
The static resource file callback
does not return a JS file in the form of an execution function after the added GET parameter, so the load fails.
App.veishu.com/jsonp/categories/all.js can you put down the All.js code??
If you remember correctly, jsonp
the request requests that the data returned by the server json
be ()
wrapped up in parentheses.
Jsonp's principle is to request a section of JS, all.js syntax error.
Your app.veishu.com/jsonp/categories/all.js
return data structure is impossible to do Jsonp, JSONP should return a similar data structure callback(data);
which is data
the JSON data you want to return
"Recommended"
1. Special recommendation : "PHP Programmer Toolkit" V0.1 version download
2. PHP Free Video Tutorial
3. PHP Development Verification Code latest video tutorial