Mihaly
Mihaly

Reputation: 301

How to get rid of synchronous XHTML request?

How to rewrite the code so I can use the JSON data retrieved from test2.php?

function drawChart4() {
    var jsonData = $.ajax({
        url: "/master/test2.php?zoekopdracht=ceremonie",
        dataType: "json",
        async: false
    }).responseText;

    var object = $.parseJSON(jsonData);

Upvotes: 0

Views: 88

Answers (1)

arkascha
arkascha

Reputation: 42935

Your question is not very clear, but maybe this is what you are looking for:

$.ajax({
    url: "/master/test2.php?zoekopdracht=ceremonie",
    dataType: "json"
}).done(function(jsonData){
    // do something with the data
    console.log(jsonData);
}).fail(function(){
    // react on error
    console.log("Whoops, that failed!");
});

This assumes you are using the jQuery JS library on the client side, which your code implies.

Upvotes: 1

Related Questions