jQuery Ajax请求而不加载结果

Dam*_*ien 1 jquery

嘿所有,我真的是ajax的新手,我想做的就是调用一个不返回任何内容的ajax函数.我用过

$( '#myDiv')负载( '/ ajaxScript.asp');

并将结果加载到myDiv就好了.我只想运行ajax而不返回任何东西.只需运行我的代码.我该怎么做呢?另外,我如何检测它何时完成呢?谢谢大家!

Mar*_*lde 6

你可以使用$.ajax而不是加载; 这基本上是$(接收器).load()的别名;

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

演示代码在这里:

$.ajax({
  url: '/path/to/file',
  type: 'POST',
  dataType: 'xml/html/script/json/jsonp',
  data: {param1: 'value1'},
  complete: function(xhr, textStatus) {
    //called when complete
  },
  success: function(data, textStatus, xhr) {
    //called when successful
  },
  error: function(xhr, textStatus, errorThrown) {
    //called when there is an error
  }
});
Run Code Online (Sandbox Code Playgroud)