Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery AJAX syntax

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

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);
    }

I don't think the data: value is quite right. Someone set me straight?

Thanks!

like image 315
Nick Avatar asked Apr 23 '09 02:04

Nick


1 Answers

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){

            }

        }); 
like image 153
Kumar Mangalam Avatar answered Oct 15 '22 11:10

Kumar Mangalam