javascript - ajax cross-domain request problem

WBOY
Release: 2016-09-23 11:31:03
Original
1399 people have browsed it

The php side has header("Access-Control-Allow-Origin:*");

ajax request

<code>    $.ajax(
    {
        type : "post",
        url : url,
        async : false,
        dataType: 'json',
        data : {asdsa:1},
        success : function (obj)
        {
                //业务代码

        },
        error : function (obj) {
            alert('未找到文件');
        }
    }
    );</code>
Copy after login
Copy after login

If data is empty, for example {}, an error will be reported. The CORS header is missing 'Access-Control-Allow-Origin'

Data It’s normal to just write a parameter such as {dasdsa:1}. What’s going on?
This problem did not occur when cross-domain access was not bound to a domain name on the test machine, but now it does not work if the domain name is bound online

ps. There is a difference between testing and going online. Apache is used for testing the backend, and nginx is used for going online. Does this have anything to do with it?

Reply content:

The php side has header("Access-Control-Allow-Origin:*");

ajax request

<code>    $.ajax(
    {
        type : "post",
        url : url,
        async : false,
        dataType: 'json',
        data : {asdsa:1},
        success : function (obj)
        {
                //业务代码

        },
        error : function (obj) {
            alert('未找到文件');
        }
    }
    );</code>
Copy after login
Copy after login

If data is shorted, for example {}, an error will be reported. The CORS header is missing 'Access-Control-Allow-Origin'

Data Just write a parameter such as {dasdsa:1} and it's normal. What's going on?
This problem did not occur when cross-domain access was not bound to a domain name on the test machine, but now it does not work if the domain name is bound online

ps. There is a difference between testing and going online. Apache is used for testing the backend, and nginx is used for the backend going online. Does this have anything to do with it?

I don’t know what you mean by cross-domain. Ajax can only operate within the root directory.

It feels like an ajax cache problem, and the cross-domain should be jsonp

Is it a server-side error or a client-side error reported in the network?

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!