Today, when JQuery Ajax is used to obtain remote server data on a local computer, $. ajax, $. getJSON, $. get did not respond to these issues. Then I tested the code on a unified website. Later I thought about it. I have a cross-origin statement.
After Baidu, the problem is solved. Here we will summarize and add it to favorites:
Same Domain Name:
$.getJSON("GetDeviceRealData.aspx?deviceid=" + deviceid + "&rtype=json", function(data) { $.each(data.list, function(i, o) { html.push(o.name + ":" + o.value + o.unit + "<br/>"); }); $("#divdata").html(html.join('')); });
In this way, data can be obtained and l is displayed.
Different domain names:
var pilot = { getdata: function(deviceid) { var html = []; $.getJSON("http://www.aaa.com/GetDeviceRealData.aspx?deviceid=" + deviceid + "&rtype=json&jsoncallback=?", function(data) { $.each(data.list, function(i, o) { html.push(o.name + ":" + o.value + o.unit + "<br/>"); }); $("#divdata").html(html.join('')); }); }}
Important Notes:
1. Add jsoncallback =? (Or callback = ?)
2. When http://www.aaa.com/getdevicerealdata.aspxreturns to json, Add:
string jsonb = Request["jsoncallback"];....Response.Write(jsonb + "(" + responseText + ")");
In this way, you can get and display the data normally.