0

我有如下代码:

jQuery.ajax({
    url: '/Control/delete',
    type: 'GET',
    contentType: 'application/json',
    success: function (bool) {
        if (bool == "deleted") {
            alert('record deleted');
            $(".row" + currentId).hide('slow');
        }
        else {
            alert('not deleted ');
        }
    }
});

例如,我需要使用 GET 发送 file_id (?file_id=12) 参数,我该怎么做?

4

6 回答 6

3

使用data选项:

jQuery.ajax({
  type: 'GET',
  data: {file_id : 12},
  ......
});

http://api.jquery.com/jQuery.ajax/

于 2012-07-04T11:24:08.780 回答
3

使用data参数

jQuery.ajax({
  url: '/Control/delete',
  type: 'GET',
  contentType: 'application/json',
  data: {file_id: 12}
  success: function (bool){
  if(bool == "deleted"){
    alert('record deleted');
    $(".row"+currentId).hide('slow');
  }
  else{
    alert('not deleted ');                  
  }
 }
});

也不是data这样的查询字符串:

data: "file_id=12&foo=bar"

如果它不是查询字符串,jQuery 会自动将其转换为查询字符串。

要发送到服务器的数据。如果还不是字符串,则将其转换为查询字符串。

jQuery.ajax 文档

于 2012-07-04T11:24:20.837 回答
1

将此替换 url 与 /url/delete?file_id=12 一起使用

jQuery.ajax({
      url: '/Control/delete?file_id=12',
      type: 'GET',
      contentType: 'application/json',
      success: function (bool){
      if(bool == "deleted"){
        alert('record deleted');
        $(".row"+currentId).hide('slow');
      }
      else{
        alert('not deleted ');                  
      }
     }
    });
于 2012-07-04T11:24:20.933 回答
0

只需将其添加到 URL:

url: '/Control/delete?file_id=12',
于 2012-07-04T11:23:56.820 回答
0

使用dataajax 调用的选项并将其传递给带有键值对的对象。

于 2012-07-04T11:25:09.107 回答
0
//POST METHOD

$.ajax({
  type: 'POST',
  data: {file_id : 12},
  ......
});

//GET METHOD

$.ajax({
  type: 'GET',
  data: "file_id=12&someother=othervalue",
  ......
});
于 2012-07-04T11:32:31.623 回答