Home Web Front-end JS Tutorial How Ajax calls restful interface to transmit Json format data (with code)

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

May 23, 2018 pm 04:24 PM
ajax javascript restful

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

How to solve the 403 error encountered by jQuery AJAX request

How to solve jQuery AJAX request 403 error How to solve jQuery AJAX request 403 error Feb 19, 2024 pm 05:55 PM

How to solve jQuery AJAX request 403 error

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

How to get variables from PHP method using Ajax?

PHP vs. Ajax: Solutions for creating dynamically loaded content PHP vs. Ajax: Solutions for creating dynamically loaded content Jun 06, 2024 pm 01:12 PM

PHP vs. Ajax: Solutions for creating dynamically loaded content

How to solve the problem of jQuery AJAX error 403? How to solve the problem of jQuery AJAX error 403? Feb 23, 2024 pm 04:27 PM

How to solve the problem of jQuery AJAX error 403?

Understanding Ajax Frameworks: Explore Five Common Frameworks Understanding Ajax Frameworks: Explore Five Common Frameworks Jan 26, 2024 am 09:28 AM

Understanding Ajax Frameworks: Explore Five Common Frameworks

Asynchronous data exchange using Ajax functions Asynchronous data exchange using Ajax functions Jan 26, 2024 am 09:41 AM

Asynchronous data exchange using Ajax functions

PHP and Ajax: Ways to Improve Ajax Security PHP and Ajax: Ways to Improve Ajax Security Jun 01, 2024 am 09:34 AM

PHP and Ajax: Ways to Improve Ajax Security

See all articles