jQuery Ajax请求而不加载结果

时间:2011-06-02 03:04:01

标签: jquery

嘿所有,我真的是ajax的新手,我想做的就是调用一个不会返回任何东西的ajax函数。我用过

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

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

2 个答案:

答案 0 :(得分: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
  }
});

答案 1 :(得分:2)

使用简单的功能:

jQuery.post("{url}", {parameters}, function(data, status){}, "text");

jQuery.get("{url}", {parameters}, function(data, status){}, "text");

请参阅http://api.jquery.com/jQuery.post/http://api.jquery.com/jQuery.get/。当请求返回时,将调用该函数。