Is there a way to use setTimeout in this ajax call. This is my code:
jQuery.ajax({
type : "POST",
url : dir+"all/money/myFile.php",
data : "page="+data.replace(/\&/g, '^'),
success : function(msg) {
var info = jQuery('.product_overview #allinfo').html();
var url = '<a href=".php?preview='+msg+'.html" target="_blank" class="check_link_preview" rel="'+msg+'.html">Check Preview</a>'; jQuery('.option_additional').next().find('textarea:first').text(info+url);
},
plete: function() {
jQuery('.add-to-cart button.btn-cart').delay(500).trigger('click');
}
});
I want to do something before this ajax will be triggered that is why I'll use setTimeout or something that would delay this action.
How would I do that?
Thanks in advance :)
Is there a way to use setTimeout in this ajax call. This is my code:
jQuery.ajax({
type : "POST",
url : dir+"all/money/myFile.php",
data : "page="+data.replace(/\&/g, '^'),
success : function(msg) {
var info = jQuery('.product_overview #allinfo').html();
var url = '<a href="http://www.mySite./openMe/letmeview.php?preview='+msg+'.html" target="_blank" class="check_link_preview" rel="'+msg+'.html">Check Preview</a>'; jQuery('.option_additional').next().find('textarea:first').text(info+url);
},
plete: function() {
jQuery('.add-to-cart button.btn-cart').delay(500).trigger('click');
}
});
I want to do something before this ajax will be triggered that is why I'll use setTimeout or something that would delay this action.
How would I do that?
Thanks in advance :)
Share Improve this question asked Aug 8, 2011 at 6:36 PinoyStackOverflowerPinoyStackOverflower 5,30218 gold badges66 silver badges134 bronze badges 6- So if you want to use it - why didn't you just do that?! ;-) – zerkms Commented Aug 8, 2011 at 6:38
- @zerkms: How would I put it in a setTimeout function? – PinoyStackOverflower Commented Aug 8, 2011 at 6:39
- Can you show me an example please using my code above. Thanks :) – PinoyStackOverflower Commented Aug 8, 2011 at 6:44
- uhm, have you ever used setTimeout? – zerkms Commented Aug 8, 2011 at 6:44
- 1 any reason for that? "Won't work" is not an explanation of an issue. – zerkms Commented Aug 8, 2011 at 6:47
4 Answers
Reset to default 2Haven't used jquery with setTimeout before but try
var t = window.setTimeout(function, delay);
replace function in the above code with your jquery function.
In a plete function:
plete: function () {
setTimeout(function () {
// your action here
}, 500);
}
You can use beforeSend
,
Example
$(function() {
function callBeforeAjax() {
alert('and now do ajax');
}
$.ajax({
beforeSend: callBeforeAjax,
type: "POST",
url: "/",
data: "",
success: function(msg) {},
plete: function(msg) {
alert(msg);
}
});
});
Refer this
@Tols is right, it works. Try something like this: setTimeout(function(){jQuery('.add-to-cart button.btn-cart').trigger('click');}, 500);