Home > Web Front-end > JS Tutorial > body text

How Ajax calls restful interface to transmit Json format data (with code)

亚连
Release: 2018-05-23 16:24:26
Original
5137 people have browsed it

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){ 
    //调用失败 
  } 
});
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template