For packaging jquery ajax

The first layer encapsulating $ .ajax ({name attribute: value, attribute name: value})

/ * 
Url: requests the server address 
data: request parameter 
dataType: server returns the data type of 
error request error functions performed by the 
success request successful execution of the function, function (data) data server back to 
back data. 
Of the type: Request mode 
* / 
$ ( ' A. ") the Click ( function () { 
    $ .ajax ({ 
        URL: 'Demo' , 
        Data: { " name ":" Joe Smith " }, 
        dataType: 'HTML' , 
        error: function () { 
            Alert ( " request error. " ) 
        }, 
        success: function (Data) { 
            Alert ( " request was successful "+data)
        },
        type:'POST'
    });
    return false;
})

A second layer encapsulating $ .get (url, data, success, dataType)) 1 $ .post (url, data, success, dataType))

$("a").click(function(){
    $.post({
        url:'demo',
        data:{"name":"张三"},
        function(data){
            alert("请求成功"+data)
        },
        dataType:'html'
    })
})

The third layer package $ .getJSON (url, data, success). $ .GetScript (url, data, success)

Guess you like

Origin www.cnblogs.com/yuming2018/p/11325905.html