如何使用ajax和jquery重定向URL?

编程入门 行业动态 更新时间:2024-10-28 00:25:57
本文介绍了如何使用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 = "www.example";

因此,在您的if语句中,请使用上述脚本进行重定向

So in your if statement use above script for redirection

if(answer_from_actionpage == 1){ window.location.href = "www.example"; }

更多推荐

如何使用ajax和jquery重定向URL?

本文发布于:2023-10-10 12:01:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478614.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   重定向   jquery   ajax   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!