mva*_*sco 2 javascript php ajax jquery
这是我用来使用Ajax将参数传递给另一个PHP页面的脚本.
$(document).on( "click",".btndriver", function() {
var id = $(this).attr("id");
var nombre = $(this).attr("nombre");
var url = "ondemand_driver.php";
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
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
但现在网址没有收到任何参数.
为了检查它,我包括:
<?php echo $_POST['id'];?>
Run Code Online (Sandbox Code Playgroud)
在ondemand.driver.php,没有显示任何值.
我还检查了var id的值,它是45.
先感谢您.
尝试以下解决方案:
$(document).on( "click",".btndriver", function() {
var id = $(this).attr("id");
var nombre = $(this).attr("nombre");
var url = "ondemand_driver.php";
swal({
title: "Select Driver?",
text: "Select Driver? : "+nombre+" ?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "GO",
closeOnConfirm: true },
function(){
var value = {
'id': id
};
var newForm = $('<form>', {
'action': url,
'target': '_top',
'method': 'POST'
}).append($('<input>', {
'name': 'id',
'value': id,
'type': 'hidden'
}));
$(document.body).append(newForm);
newForm.submit();
});
});
Run Code Online (Sandbox Code Playgroud)
这提交了一个动态创建的表单,而不是发送2个单独的请求,如redirect和ajax.