2017-10-08 10 views
0

私はjsonのためにdocument.write()を使用します。アヤックスの外でdocument.write(JSON.stringify({name:'jason',surname:'etc'}));で作業しますが、.done()では動作しません。 dataType:'json'を削除しようとしましたが、動作しません。JSON.stringify in jquery ajax

$.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"); 
}); 
+0

'done' – prasanth

+0

https://www.w3schools.com/jsref/met_doc_write.asp私はおそらく文書準備した後、あなたカント利用のdocument.writeを考える代わりに、' SUCCESS'を試してみてください。 jqueryを使用して、ページの一部の要素にコンテンツを変更または追加することができます。 – Surely

+0

@prasanth私は試してみましたが動作しません。実際にはコードは仕事ですが、私はページに生のjsonを書きたいと思います。 html> bodyで記述します。それは成功の外に生のjsonを書くか、または機能を終了しました。どのようにページに生のjsonを書くか。 html> bodyなし。 – bukalemun

答えて

0

、あなたのブラウザのコンソールをチェックすると、次のエラーが表示されるはずです...

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.

httpから httpsにプロトコルにあなたのURLを変更

。動作するはず

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

。あなたはjQueryのgetJSONを使用していないのはなぜ

Working Demo

+0

コンソールでエラーが発生しません。 httpをhttpsに変更しますが、動作しません。 – bukalemun

+0

@bukalemun、リンク – dcodesmith

0

$.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); 
}) 
+0

を確認してください。実際にはコードは動作しますが、ページ上に未処理のjsonを書きたいと思います。 html> bodyで記述します。それは成功の外に生のjsonを書くか、または機能を終了しました。 – bukalemun