[英]Open URL after success in Ajax function
I am trying to open an URL from an Ajax function, but the URL is not called. 我正在尝试从Ajax函数打开URL,但是未调用该URL。
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? 那里怎么了
You can't just call an object property key like that. 您不能只这样调用对象属性键。 It's not a variable.
这不是一个变量。
Just do this: 只要这样做:
var url = "ondemand_driver.php";
$.ajax({
url : url,
type: "POST",
data : value,
success: function() {
window.location = url;
}
});
Declared the url as variable out of ajax function 从ajax函数中将url声明为变量
var url = "ondemand_driver.php";
$.ajax(
{
url : url,
type: "POST",
data : value,
success: function() {
window.location(url);
}
});
its work fine. 它的工作很好。
您需要将url定义为变量,只有ajax请求成功时才会打开url。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.