ajax cross domain not working in jquery

前端 未结 3 1965
自闭症患者
自闭症患者 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 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);
        }
    });
    

提交回复
热议问题