Home > Web Front-end > JS Tutorial > body text

Use jsonp to perfectly solve cross-domain problems_javascript skills

WBOY
Release: 2016-05-16 16:30:07
Original
1256 people have browsed it

Call the web interface, get request, and find the prompt: No 'Access-Control-Allow-Origin' header is present on the requested resource.

This is related to the security mechanism, cross-domain calls are not allowed by default

Processing method: Use jsonp format, ajax request parameter dataType:'JSONP'.

Copy code The code is as follows:

$.ajax({
​ ​ url: "http://.......",
        type: 'GET',
         dataType: 'JSONP',//here
Success: function (data) {

}
});


Hey, this is really difficult for those who don’t know it, but it’s not difficult for those who know it. A simple line of code solves this big problem. . . . Cry~

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!