I'm working on some code that need to retrieve data from API. The idea is get json data and decode it when I have the data, I've done this before using file_get_contents and json_decode on PHP.
For the detail:
I need that code for seat reservation that user could choose their own seat.So I made the seat map with table and the "td" is clickable. It all works fine except for the API thing. What I want is when the seat already clicked/chosen I retrieve data from API.
I've tried:
$.getJSON(jos, function(jd) {
var hah = $.parseJSON(jd);
alert(jd);
});
$.ajax({
url: jos,
})
.done(function(data) {
alert('data');
});
note: jos is variable that contains url for my API
I'll appreciate any response
you don't need to convert the data from $.getJSON()
to JSON, since it already is a JSON string:
$.getJSON(jos, function(jd) {
alert(jd);
});
$.ajax(
url: jos,
dataType: "json",
success: function(data){
alert(data);
}
);
Specifying dataType as json means that the you are expecting a json object from the server.
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.