簡體   English   中英

jQuery ajax中的JSON.stringify

[英]JSON.stringify in jquery ajax

我將document.write()用於json。 document.write(JSON.stringify({name:'jason',surname:'etc'})); 在ajax之外,但在.done()不起作用。 我嘗試刪除dataType:'json'但不起作用。

$.ajax({
    url: "http://api.wunderground.com/api/24b969202160514e/geolookup/conditions/q/Turkey/zmw:00000.58.17352.json",
    dataType:'json'
})
.done(function(data) {
    console.log("success",data);
    document.write(JSON.stringify(data));
    //document.write(data);
})
.fail(function(data) {
    console.log("error",data);
})
.always(function() {
    console.log("complete");
});

如果您檢查瀏覽器控制台,則應該看到以下錯誤...

jquery-git.js:9648 Mixed Content: The page at 'https://jsfiddle.net/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.wunderground.com/api/24b969202160514e/geolookup/conditions/q/Turkey/zmw:00000.58.17352.json'. This request has been blocked; the content must be served over HTTPS.

將您的url協議從http更改為https

https://api.wunderground.com/api/24b969202160514e/geolookup/conditions/q/Turkey/zmw:00000.58.17352.json

那應該工作。

工作演示

為什么不使用jQuery的getJSON

$.getJSON('https://api.wunderground.com/api/24b969202160514e/geolookup/conditions/q/Turkey/zmw:00000.58.17352.json')
.done(function(data) {
    console.log("success",data);
    document.write(JSON.stringify(data));
    //document.write(data);
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM