如何使用ajax和jquery重定向URL? [英] How to redirect url using ajax and Jquery?
本文介绍了如何使用ajax和jquery重定向URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在数据提交上重定向URL.这是我的PHP代码:
I am trying redirect URL on data submit. Here is my PHP code:
<?php
$error = array();
$user_id=$_SESSION['email'];
$apply_id=$_SESSION['id'];
$purpose_amount=$_POST['purpose_amount'];
$amount=$_POST['amount'];
$cheque_name=$_POST['cheque_name'];
if(empty($amount)){
$error[] = "Please Enter Expected Amount";
}
elseif(empty($cheque_name)){
$error[] = "Please Enter Issue Cheque in Favour of";
}
if (count($error)) {
echo "<i class='fa fa-exclamation'> ";
echo implode('<br>', $error);
echo "</i>";
}
else{
$result=mysqli_query($conn, "UPDATE education SET amount='$amount', cheque_name='$cheque_name', purpose_amount='$purpose_amount', date='$date' WHERE id='$apply_id'")or die("Could not insert data: " .mysqli_error($conn));
echo 1;
}
?>
这是JQuery和AJAX代码:
And here is JQuery and AJAX code:
$('.btn_education_step5').click(function(){
var formdata=new FormData($('#education_step5')[0]);
$.ajax({
url:'includes/backend_education_amount.php',
method: "POST",
async: false,
cache: false,
contentType: false,
processData: false,
data : formdata,
success:function(answer_from_actionpage){
if(answer_from_actionpage == 1){
Redirect url code??????
}else{
$('.error').html(answer_from_actionpage);
}
}
})
});
提交数据后,我想重定向URL,例如abc.php?id=$user_id
我可以在success:function()
中做些什么来重定向URL.
When my data is submitted I want to redirect URL like this abc.php?id=$user_id
What can I do in success:function()
to redirect URL.
推荐答案
您可以使用以下JavaScript脚本将当前页面重定向到任何url
You can redirect current page to any url by using following JavaScript script
window.location.href = "http://www.example.com";
因此,在您的if语句中,请使用上述脚本进行重定向
So in your if statement use above script for redirection
if(answer_from_actionpage == 1){
window.location.href = "http://www.example.com";
}
这篇关于如何使用ajax和jquery重定向URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文