JavaScript ajax scripting Cross-domain call detailed

Source: Internet
Author: User
Tags error handling json script tag in domain

I finally got a little time today. Javsscript Ajax Script Cross-domain call problem, first on the internet to find some of the solution, but are more complex. The problem with Ajax Cross-domain calls is found in some snippets from the Jquery.chm user's manual. The code snippet is as follows:

Crossdomain mapV1.5

Default: Same-domain request is false

Cross-domain request is true if you want to force Cross-domain requests (such as Jsonp form) to the same domain, set Crossdomain to True. This makes the server side, for example, directed to another domain.

The emphasis here is on AJAX-enabled Cross-domain calls, datatype must be in the JSONP format. (What is JSONP here do not explain, you can Google it.) )

There are some snippets of code outside the order:

DataType String

The type of data expected to be returned by the server. If not specified, JQuery will automatically intelligently judge against HTTP packet mime information, such as XML MIME types being recognized as XML. In 1.4, JSON generates a JavaScript object, and script executes it. The data returned by the server side is then parsed against this value and passed to the callback function. Available values:

"XML": Returns an XML document that can be processed with jQuery.

HTML: Returns plain text HTML information, and the included script tag executes when the DOM is inserted.

Script: Returns the plain text JavaScript code. Results are not automatically cached. Unless the "cache" parameter is set. ' Note: ' At remote request (not in the same domain), all post requests will be converted to get requests. (because it will be loaded using the DOM's script tag)

"JSON": Returns JSON data.

"JSONP": Jsonp format. When calling a function using the JSONP form, such as "Myurl? Callback=? "JQuery will automatically replace? To the correct function name to execute the callback function.

' Text ': Returns a plain text string

Jsonp String

Overrides the name of the callback function in a JSONP request. This value is used to replace the "callback=?" The "callback" section of the URL parameter in this get or POST request, such as {jsonp: ' Onjsonpload '}, will cause the "onjsonpload=?" passed to the server.

Jsonpcallback String

Specifies a callback function name for the JSONP request. This value will be used to replace the random function name that jquery automatically generates. This is primarily used to allow jquery to generate unique function names, which makes it easier to manage requests and easily provides callback functions and error handling. You can also specify this callback function name when you want the browser to cache a GET request.

The above several important code snippets, focusing on the Red Word section, require that Ajax be invoked across domains to specify a callback handler function.

See so many people must be tired of watching, directly to the above code combination. This code is in domain: test.com, now call http://jks.com/JsTest.aspx for AJAX validation. The code is as follows:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.