JQuery AJAX syntax

前端 未结 9 1868
旧时难觅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 20:42

    Though not a direct answer to your question, following is the common function approach used in one of our projects for jquery calls

    $.proxy() Method

    The Proxy method takes an existing function and returns a new one with a particular context.

    Syntaxes

    $(selector).proxy(function,context)
    $(selector).proxy(context,name)  
    

    CODE

    dpInvokeAsync: function (serviceRequest, input, requestType, successCallBack) {
            var url = BASE_URL + serviceRequest;
            $.ajax({
                type: requestType,
                url: url,
                async: true,
                data: input,
                dataType: 'json',
                success: $.proxy(successCallBack, this),
                error:  $.proxy(this.handleFailure, this)
            });
        }
    
    
       this.dpInvokeAsync('App/ShowParts', searchCriteria, 'Post',
                          function (result) { alert(result);}
                          );
    

    REFERENCES

    1. $(this) inside of AJAX success not working
    2. jQuery Cross-Domain AJAX Request methods

提交回复
热议问题