How to get a cross-origin resource sharing (CORS) post request working

后端 未结 11 2232
野趣味
野趣味 2020-11-21 22:35

I have a machine on my local lan (machineA) that has two web servers. The first is the in-built one in XBMC (on port 8080) and displays our library. The second server is a

11条回答
  •  一生所求
    2020-11-21 23:22

    Took me some time to find the solution.

    In case your server response correctly and the request is the problem, you should add withCredentials: true to the xhrFields in the request:

    $.ajax({
        url: url,
        type: method,
        // This is the important part
        xhrFields: {
            withCredentials: true
        },
        // This is the important part
        data: data,
        success: function (response) {
            // handle the response
        },
        error: function (xhr, status) {
            // handle errors
        }
    });
    

    Note: jQuery >= 1.5.1 is required

提交回复
热议问题