[英]How to redirect a user to another page within the CMS
I am developing a content management system (CMS). 我正在开发内容管理系统(CMS)。 I did this with php, but now I want to add jquery because I don't want page reload when a form is submitted.
我是用php完成的,但是现在我想添加jquery,因为我不希望在提交表单时重新加载页面。 I can submit a form using jquery.
我可以使用jquery提交表单。 What I want now is after form is submitted to take the user to a different page (desired_page.php) within the CMS, replacing the page that contains the form.
我现在想要的是在提交表单后将用户带到CMS中的其他页面(desired_page.php),替换包含表单的页面。 I can do this with php using window.open('index.php?desired_page','_self'), but I don't know how to do this with jquery.
我可以使用window.open('index.php?desired_page','_ self')用php做到这一点,但是我不知道如何用jquery做到这一点。 window.location.replace("desired_page.php") actually redirected me to desired_page.php, but outside the CMS.
window.location.replace(“ desired_page.php”)实际上将我重定向到了desired_page.php,但在CMS之外。 How can I replace the form with desired_page.php after form is submitted?
提交表单后,如何将表单替换为required_page.php? My codes are shown below:
我的代码如下所示:
HTML 的HTML
<form action="set_date_form.php" id="setdate" method="post" >
<input type="text" name="date" id="datetimepicker" placeholder="Choose Date" class="form-control" maxlength="2" required/>
<button id="subdate"class="btn btn-default" ><b>Set Date</b></button>
</form>
Javascript Java脚本
$('body').on('click', '#subdate', function(){
$.post($("#setdate").attr("action"), $("#setdate").serialize(), function(info){ $("#resultm").html(info); } );
clearInput();
pageRedirect();
});
$('body').on('submit', '#setdate', function(event){
event.preventDefault();
return false;
});
function pageRedirect() {
window.location.replace("sent_messages.php");
}
setTimeout("pageRedirect()", 10000);
function clearInput() {
$("#setdate")[0].reset();
}
While using window.location.replace You need to specifies the FULL URL of the page to navigate to it. 使用window.location.replace时,需要指定页面的完整URL才能导航到该页面。
for eg: window.location.replace(" http://www.example.com/sent_messages.php "); 例如:window.location.replace(“ http://www.example.com/sent_messages.php ”);
如果您要用desirable_page.php替换表单,请使用Jquery Load替换表单中的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.