Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jqueryajax发送GET值?_Jquery_Ajax - Fatal编程技术网

如何使用jqueryajax发送GET值?

如何使用jqueryajax发送GET值?,jquery,ajax,Jquery,Ajax,我的代码如下: jQuery.ajax({ url: '/Control/delete', type: 'GET', contentType: 'application/json', success: function (bool) { if (bool == "deleted") { alert('record deleted'); $(".row" + currentId).hide('slow'

我的代码如下:

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 ');
        }
    }
});
aa例如,我需要使用GET发送file_id(?file_id=12)参数,我如何才能这样做?

只需将其添加到URL:

url: '/Control/delete?file_id=12',

使用
数据
选项:

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

使用
数据
参数

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: "file_id=12&foo=bar"
如果不是查询字符串,jQuery将自动将其转换为查询字符串

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


使用此url替换为/url/delete?文件\u 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 ');                  
      }
     }
    });

使用ajax调用的
data
选项,并将一个对象与键值对一起传递给它。

实际的GET方法
data:“file\u id=12&someother=othervalue”
好的,那么如何编写文章呢method@ubercooluk当前位置阅读文档:)你所说的是另一种方式
//POST METHOD

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

//GET METHOD

$.ajax({
  type: 'GET',
  data: "file_id=12&someother=othervalue",
  ......
});