Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
563 views
in Technique[技术] by (71.8m points)

jquery - Unable to post data using JSONP on Cross Domain

We have a scenario where we need to post data from our domain (x.com) to a different domain (y.com). The action on the y.com is attributed HTTPPost and it can be changed. But while posting data to the y.com using AJAX and JSONP with HTTPMethod POST the request is automatically converted to HTTPMethod GET.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can't POST using JSONP (look here and here) because it just doesn't work that way - it creates a <script> element to fetch data, which has to be done via GET request. JSONP solution doesn't use XmlHttpRequest object, so it is not an AJAX request in the standard way of understanding, but the content is still accessed dynamically - no difference for the end user.

JSONP can be indeed used to overcome same origin policy restriction, but alternatively you can use CORS, implemented in modern browsers alternative to JSON with Padding.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...