Question about jquery cross-origin call to the rest Service

Source: Internet
Author: User

Previously, jquery's Ajax request was used to access rest, and "Get/Post" was used to send HTTP requests. The server always received the "option" method. I learned on the Internet that cross-origin is actually the cause. The result is that neither HTTP header nor Params can be obtained.

Then, I checked the cross-origin call of jquery and found that jsonp can be used,CodeAs follows:

VaR Postdata = { ' Authorization ' : ' AWS cuimeng1: 1232432453 ' }
VaR Ddate = " Wed, 01 Mar 2009 12:00:00 GMT " ;
$. Ajax ({
URL: host_url,
Type: ' Get ' ,
Datatype: ' Jsonp ' ,
Jsonp: ' Callback ' ,
Data: postdata,
Header :{
" Authorization " : " AWS cuimeng1: 1232432453 "
},
Beforesend: function (xhr ){
Xhr. setRequestHeader ( " Date " , Ddate );
Xhr. setRequestHeader ( " Authorization " , " AWS cuimeng1: 1232432453 " );
},
Success: function (result ){
Alert ( ' OK ' );
},
Error: function (xhr, textstatus, errowthrown ){
Alert (xhr. status );
Alert (textstatus );
}
});

 

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.