Home > Article > Web Front-end > How Ajax calls restful interface to transmit Json format data (with code)
This article mainly introduces the relevant information on the method of Ajax calling restful interface to transmit Json format data. It is very good and has reference value. Interested friends should take a look at it.
ajax transmits json format data , the key is to specify the contentType. If the data is in json format
If it is a restful interface, change the type to the corresponding post (add), delete (delete), put (change), get (check)
var post_data={"name":"test001","pass":"xxxx"}; $.ajax({ url: "http://192.168.10.111:8080/uc/login", type: 'post', contentType: "application/json; charset=utf-8", data:JSON.stringify(post_data), success:function (data) { //调用成功 }, error: function(data, textStatus, errorThrown){ //调用失败 } });
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Ajax and cgi communication under Boa server (graphic tutorial)
Ajax Struts2 implementation verification Code verification function (graphic tutorial)
Ajax click to continuously load the data list (graphic tutorial)
The above is the detailed content of How Ajax calls restful interface to transmit Json format data (with code). For more information, please follow other related articles on the PHP Chinese website!