Sending multiple data parameters with jQuery AJAX

前端 未结 7 664
一个人的身影
一个人的身影 2020-11-29 22:00

I am sending an ajax request to a php file as shown here:

function checkDB(code, userid)
{

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

        
7条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 22:37

    Here is how POST data should be formatted:

    key1=value1&key2=value2&key3=value3
    

    In your case (note the & as a separator):

    'code=' + code + '&userid=' + userid
    

    But jQuery does that for you if you specify your data as an object:

    data: { code: code, userid: userid }
    

提交回复
热议问题