简体   繁体   中英

get the return value of success in Iron-Ajax after POST

I'm currently working the project using Polymer and I'd like to get the return value of API after POST using Iron-Ajax.

Here is my sample code,

var rs = $.ajax({
    type: "POST",
    url: apiUrl,
    data: _data,
    dataType: "json",
    contentType: 'application/json'
});

rs.done(function (data) {
    console.log(data);
    alert(data);
    }
});

Ajax is asynchronous by default,you need add async:false to make it synchronous

var rs = $.ajax({
    type: "POST",
    url: apiUrl,
    data: _data,
    async:false,
    dataType: "json",
    contentType: 'application/json'
});

var result = null;
rs.done(function (data) {
    console.log(data);
    alert(data);
    result = data;
    }
});

//return result;//you can return value like this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM