This time I will bring you the method of Ajax's restful interface to transmit Json data. What are the things to note when Ajax calls the restful interface to transmit Json data? The following is a practical case, let's take a look. 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 (increase),
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){
//调用失败
}
});
Recommended reading:
How to implement native AJAX encapsulation
##How does Ajax+Struts2 implement user input verification code verification function
The above is the detailed content of Ajax restful interface method of transmitting Json data. For more information, please follow other related articles on the PHP Chinese website!