ajax cross domain not working in jquery

前端 未结 3 1952
自闭症患者
自闭症患者 2021-01-03 12:16

Error :

Response to preflight request doesn\'t pass access control check: The \'Access-Control-Allow-Origin\' header contains multip

相关标签:
3条回答
  • 2021-01-03 12:41

    The headers you send to the server from Javascript, should be returned by the server. If you have no access to the server this will be impossible. This means the server accepts your domain as a legal processor.

    Next to that you can try a JSONP call. Check this URL: https://learn.jquery.com/ajax/working-with-jsonp/

    0 讨论(0)
  • 2021-01-03 12:56

    you can't do ajax operaitons on other websites source code except you have rights. you have to to that on the server side. in php you can use cURL, in .net you can use html agility pack.

    0 讨论(0)
  • 2021-01-03 13:02

    Please use JSONP for cross domain scripting.

    Check below sample code:

    $.ajax({
        url: "http://example.com/" + $("#selector3").val(),
        type: "GET",
        dataType: 'jsonp', // Notice! JSONP <-- P (lowercase)
        data: request,
        processData: true,
        data: {},
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Headers": "origin, content-type, accept"
        },
        success: function(data) {
            alert(data.Company_Id);
        }
    });
    
    0 讨论(0)
提交回复
热议问题