JQuery AJAX syntax

前端 未结 9 1870
旧时难觅i
旧时难觅i 2021-01-17 20:11

I am trying to find the correct syntax to pass a varible to my JQuery Post.

var id = empid;

$.ajax({
    type: \"POST\",
    url: \"../Webservices/EmployeeS         


        
相关标签:
9条回答
  • 2021-01-17 21:01

    How about this:

    var id = empid;
    
    $.ajax({
        type: "POST",
        url: "../Webservices/EmployeeService.asmx/GetEmployeeOrders",
        data: "{empid: " + empid + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result){
            alert(result.d);
            console.log(result);
        }
    });
    
    0 讨论(0)
  • 2021-01-17 21:03

    Complete ajax syntax

    var data="abc";
           $.ajax({
                type: "GET",
                url: "XYZ",
                data: {
                    "data":data,
                },
                dataType: "json",
    
                //if received a response from the server
                success: function( datas, textStatus, jqXHR) {
    
                },
    
                //If there was no resonse from the server
                error: function(jqXHR, textStatus, errorThrown){
    
                },
    
                //capture the request before it was sent to server
                beforeSend: function(jqXHR, settings){
    
                },
    
                //this is called after the response or error functions are finished
                //so that we can take some action
                complete: function(jqXHR, textStatus){
    
                }
    
            }); 
    
    0 讨论(0)
  • 2021-01-17 21:05

    you can use the following.

    var id = empid;
    
    $.ajax({
        type: "POST",
        url: "../Webservices/EmployeeService.asmx/GetEmployeeOrders",
        data: "var1=val1&var2=val2&var3=val3&var4=val4&var5=val5",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            alert(result.d);
        }
    
    0 讨论(0)
提交回复
热议问题