jQuery Cross Domain Ajax

前端 未结 7 1932
Happy的楠姐
Happy的楠姐 2020-12-09 05:06

My ajax code is

$.ajax({
    type: \'GET\',
    dataType: \"jsonp\",
    processData: false,
    crossDomain: true,
    jsonp: false,
    url: \"http://someo         


        
7条回答
  •  孤城傲影
    2020-12-09 05:38

    The response from server is JSON String format. If the set dataType as 'json' jquery will attempt to use it directly. You need to set dataType as 'text' and then parse it manually.

    $.ajax({
        type: 'GET',
        dataType: "text", // You need to use dataType text else it will try to parse it.
        url: "http://someotherdomain.com/service.svc",
        success: function (responseData, textStatus, jqXHR) {
            console.log("in");
            var data = JSON.parse(responseData['AuthenticateUserResult']);
            console.log(data);
        },
        error: function (responseData, textStatus, errorThrown) {
            alert('POST failed.');
        }
    });
    

提交回复
热议问题