我有一个 AJAX 函数(如下)。我正在尝试将输入从一页传递到另一页。
它将我重定向到另一个页面,但没有传递所需的值。
我不明白为什么它没有像我预期的那样工作。
我正在寻找另一种方法来做到这一点。任何帮助将不胜感激。
//second page
<?php
$cuit = $_POST['cuit'];
?>
<input id="act" type="text" class="form-control" value="<?php echo $cuit ?>">
function mod(id, origen) {
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false
}).then(function() {
if (origen == "perfiles") {
$.post("api/eliminar_perfil.php", {
id: id
}, function(mensaje) {
$("#tr_" + id).remove();
});
} else if (origen == "index") {
$.ajax({
type: "post",
url: "perfiles.php",
data: {
cuit: $("#cuit").val()
},
success: function(result) {
location.href = 'http://localhost/miramonteapp/perfiles.php';
}
});
}
swal('Deleted!', 'Your file has been deleted.', 'success')
}, function(dismiss) {
// dismiss can be 'cancel', 'overlay',
// 'close', and 'timer'
if (dismiss === 'cancel') {
swal('Cancelled', 'Your imaginary file is safe :)', 'error')
}
})
}
<input id="cuit" type="text" class="form-control" onkeyup="searchCliente();">
<button id="btnBuscar" onclick="mod($('#cuit'), 'index');" type="button" class="btn btn-default" name="button">Buscar</button>
最佳答案
男孩,我认为你的解决方案更简单,如果你想使用参数重定向,则不需要 ajax 调用。
所以替换这个
$.ajax({
type : "post",
url : "perfiles.php",
data : {cuit: $("#cuit").val()},
success : function(result) {
location.href = 'http://localhost/miramonteapp/perfiles.php';
}
});
通过这个
location.href = 'http://localhost/miramonteapp/perfiles.php?cuit=' +
$("#cuit").val();
并在您的目标页面 perfiles.php
只需读取参数并使用它,您可以使用此作为指南在 JS 中读取参数 How to get the value from the GET parameters?
关于javascript - 我的 ajax 根本不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46207635/