0

I use document.write() for json. work in document.write(JSON.stringify({name:'jason',surname:'etc'})); outside the ajax, but not work in .done(). I tried remove dataType:'json' but not work.

$.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");
});
4
  • try out success instead of done Commented Oct 8, 2017 at 11:51
  • w3schools.com/jsref/met_doc_write.asp I think probably you cant use document.write after document ready. You can use jquery to modify or append the content to some element in your page. Commented Oct 8, 2017 at 12:20
  • @prasanth i try but not work. actually code is work, but i want write the raw json on the page. it write in html>body. but it write raw json outside success or done function. how to write raw json on the page. without html>body. Commented Oct 8, 2017 at 13:09
  • Use some element with print as a text. $('some element').text(yourjsonstring) Commented Oct 8, 2017 at 13:16

2 Answers 2

1

Why don't you use jQuery's 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);
})
Sign up to request clarification or add additional context in comments.

1 Comment

actually code is work, but i want write the raw json on the page. it write in html>body. but it write raw json outside success or done function.
1

If you check your browsers console, you should see the following error ...

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.

Change your url to protocol from http to https.

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

That should work.

Working Demo

2 Comments

I can't get any error in console. I change http to https but not work.
@bukalemun, check the link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.