Hey all, i'm really new to ajax and all i want to do is call an ajax function that doesn't return anything. I've used
$('#m开发者_高级运维yDiv').load('/ajaxScript.asp');
and that loads the results to myDiv just fine. I just want to run the ajax without returning anything at all. Just run my code. How do i do this? Also, how do i detect when it is done doing it's thing? Thanks all!
You can use $.ajax
instead of load; which is basically an alias of $(receiver).load();
Documentation here: http://api.jquery.com/jQuery.ajax/
Demo code here:
$.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
}
});
Use the simple functions:
jQuery.post("{url}", {parameters}, function(data, status){}, "text");
or
jQuery.get("{url}", {parameters}, function(data, status){}, "text");
See http://api.jquery.com/jQuery.post/ or http://api.jquery.com/jQuery.get/. The function will get called when the request returns.
精彩评论