admin管理员组文章数量:1353593
I am trying to open an URL from an Ajax function, but the URL is not called.
This is my code:
$(document).on( "click",".btndriver", function() {
var id = $(this).attr("id");
var nombre = $(this).attr("nombre");
swal({
title: "Select Driver?",
text: "Select Driver? : "+nombre+" ?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "GO",
closeOnConfirm: true },
function(){
var value = {
id: id
};
$.ajax(
{
url : "ondemand_driver.php",
type: "POST",
data : value,
success: function() {
window.location(url);
}
});
});
});
What is wrong there?
I am trying to open an URL from an Ajax function, but the URL is not called.
This is my code:
$(document).on( "click",".btndriver", function() {
var id = $(this).attr("id");
var nombre = $(this).attr("nombre");
swal({
title: "Select Driver?",
text: "Select Driver? : "+nombre+" ?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "GO",
closeOnConfirm: true },
function(){
var value = {
id: id
};
$.ajax(
{
url : "ondemand_driver.php",
type: "POST",
data : value,
success: function() {
window.location(url);
}
});
});
});
What is wrong there?
Share Improve this question asked Sep 26, 2017 at 10:03 mvascomvasco 5,1017 gold badges68 silver badges137 bronze badges3 Answers
Reset to default 6You can't just call an object property key like that. It's not a variable.
Change this
window.location(url)
To this
window.location = url;
Complete Code
var url = "ondemand_driver.php";
$.ajax({
url : url,
type: "POST",
data : value,
success: function() {
window.location = url;
}
});
You need to define url as variable, the url will be opened only if the ajax request is successful.
Declared the url as variable out of ajax function
var url = "ondemand_driver.php";
$.ajax(
{
url : url,
type: "POST",
data : value,
success: function() {
window.location(url);
}
});
its work fine.
本文标签: javascriptOpen URL after success in Ajax functionStack Overflow
版权声明:本文标题:javascript - Open URL after success in Ajax function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743892787a2557231.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论