Recently do the development to put the picture file on another server (another domain name), because such distributed storage, the site will open much faster. When I used Ajax to get pictures of a user on the image server, I had a problem, I couldn't get the information in the usual way, the cookie was null, and then I thought that JavaScript and IFrame could not be accessed by the browser for security reasons. Then we have to consider using other means to complete, after 2 days finally found a solution, I use JSONP to solve, please see.
JS Code:
$.ajax ({
Type: "Get",
URL: "http://www.oicqzone.com/userogin.aspx?jsoncallback=?",//Must be used here? jsoncallback=, otherwise it cannot be obtained.
Data: {"name": Name, "Pass": pass},//Here is the parameter, can not
DataType: "Jsonp",//This must, if not you can never get information
Success:function (JSON) {
var obj = eval (JSON); This is also necessary because we return with the Jsonp object, so we don't need to
Here is the decomposition of specific elements, can be set according to their own needs Jsonp object.
Alert ("Success JSON Data:" + obj.usrname + "Usrid:" + Obj.usrid + "Rndpassword:" + Obj.rndpassword);
}
});
Asp. NET code:
Note that JSON objects and values must be held with double quotes, or JS cannot get the object
String Strjson = request.querystring["Jsoncallback"] +
String. Format ({{\ "usrid\": \ "{1}\", \ "usrname\": \ "{0}\", \ "rndpassword\": \ "{2}\"}}) ",
Accounts.UserEntity.UserId, Accounts.UserEntity.UserName, Accounts.UserEntity.Password);
Context. Response.AddHeader ("Access-control-allow-origin", "*");
Response.Write (Strjson);
Using JSONP to completely solve the Ajax cross-domain access cookie session scheme