Ajax with JQuery: 200 ok, but not “success”

前端 未结 3 978
耶瑟儿~
耶瑟儿~ 2021-02-04 22:27

I\'m facing the same issue, while trying for cross-domain request. Situation is strange, my data is getting loaded while hit the requested url directly on browser, the strange p

3条回答
  •  时光说笑
    2021-02-04 23:12

    function fetchJsonData() {
    $.ajax({
        type: 'POST',
        url: "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%20%3D%20'www.meilleurmobile.com%2Fcomparateur%2Fresultats-comparateur-json.do%3FmonthDur%255B0%255D%3D45.75%26monthDur%255B1%255D%3D45.75%26monthDur%255B2%255D%3D45.75%26monthDur%255B3%255D%3D45.75%26monthDur%255B4%255D%3D45.75%26monthDur%255B5%255D%3D45.75%26monthDur%255B6%255D%3D45.75%26monthDur%255B7%255D%3D45.75%26monthDur%255B8%255D%3D45.75%26monthDur%255B9%255D%3D45.75%26monthDur%255B10%255D%3D45.75%26monthDur%255B11%255D%3D45.75%26numSms%3D1000%26dataVolume%3D1000%26withoutMobile%3D-1%26commitmentDuration%3D-1%26_%3D1329825461536'&format=json&diagnostics=true",
        async: false,
        cache: false,
        crossDomain: true,
        dataType: 'jsonp',
        error: function( xhr,err ) {
            console.log( 'Sample of error data:', err );
            console.log("readyState: "+xhr.readyState+"\nstatus: "+xhr.status+"\nresponseText: "+xhr.responseText);
        },
        success: function( data, status ) {
            if (console && console.log) {
                console.log( 'data count:', data.query.results.json.json.length );
                $('#result-count').text( JSON.stringify(data.query.results.json.json) );
            }
        },
        jsonpCallback: 'swatCallback'
    })
    .done(function() { alert("success"); })
    .fail(function() { alert("error"); }); 
    }
    
    
    window['swatCallback'] = function(data) {
        var info = data.query.results.json.json;
        $('#callback_result_operator').html(info[0].operator);
    };
    

提交回复
热议问题