Send ajax request in jquery


Use Express server

Contents in server.js:

get and post servers

Contents in server.js:

It can also be written as app.all( ' / jquery-server ' , ( request , response )=>{

                        //all can accept all types of requests such as get, post, delete, etc.


1. jQuery sends Ajax get request

html content :

Contents in server.js:

 Declare an object, convert it into a json string and pass it to the browser

 Set [type] to 'json' to set the format of the returned content

The returned result is a js object

 2. jQuery sends Ajax post request

content in html

Contents in server.js

There is also a general method:


        // Request address: url        

        url: '',

        // Parameter : data [Note that data is also an object]

        data : {a:100 ,  b:200 },    //{ a=100, b=200}

        // Request type:   type

        type : 'GET',     // 'POST'

        // Successful callback function (data) The data returned by the server

        success : function (data) {


        //Failed callback function

        error : function(){



Note: { } in () is an object , don't forget!



Guess you like