jquery $.getJSON() cross-domain request_jquery
May 16, 2016 pm 05:58 PM1. The same domain name and other requests can be the same
js:
var url="http://localhost:2589/a.ashx";
$(function(){
$.getJSON(url,function(data){
alert (data.Name);
})
});
The server returns a string:
{"Name":"loogn","Age":23}
2,
js under different domain names:
var url="http://localhost:2589/a.ashx?callback=?";
$(function(){
$.getJSON(url,function(data){
alert (data .Name);
})
});
The server returns the string:
jQuery1706543070425920333_1324445763158({"Name":"loogn","Age":23})
The returned string is a function called "jQuery1706543070425920333_1324445763158", and the parameters are {"Name":"loogn","Age":23}.
In fact, this very long function name is the function of callback=? in the request path. I think it should be like this: The $.getJSON method generates a name that references the callback method, replace it? . The above request will become
http://localhost:2589/a.ashx?callback=jQuery1706543070425920333_1324445763158&_=1324445763194. The server needs to process it when returning json, such as:
string cb = context.Request["callback"];
context.Response.Write(cb "(" json ")");
The parameter name callback can also be replaced by jsoncallback. I think it is for fear of conflict. jsoncallback should be detected first, and callback should not be detected again (not tested!!)
? It can also be a specific function name, so the callback function cannot be anonymous. Use? Generation is just a convenience provided by jQuery for our general operations.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use the Hyperf framework for cross-domain request processing

How to handle cross-domain requests and security issues in C# development

Comparative analysis of PHP Session cross-domain and cross-site request forgery

How to deal with cross-domain request issues in PHP development

How does PHP handle cross-domain requests and access control?

Cross-domain request processing in Go language framework

Solution to cross-domain access problem in Vue

How to handle cross-domain requests in Java backend function development?
