JQuery AJAX syntax

前端 未结 9 1948
旧时难觅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

    data can either be a URL encoded string or an object:

    data: {empid: empid},
    

    OR

    data: "empid=" + empid,
    

    The docs say:

    Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key i.e. {foo:["bar1", "bar2"]} becomes '&foo=bar1&foo=bar2'.

提交回复
热议问题