有什么方法可以重定向到新页面并在该页面上使用jquery编写一些内容? [英] Is there any way to redirect to a new page and write some content with jquery on that page?

查看:75
本文介绍了有什么方法可以重定向到新页面并在该页面上使用jquery编写一些内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个功能,可以在数据库中搜索航班信息.如果响应为真,我希望用户在"ticket.php"上重定向.我想使用jquery更新页面"ticket.php"的内容.但是jQuery不起作用.我在这里做错什么了吗?这是javascript的一部分.这是一个外部javascript.它同时包含在"search.php"和"ticket.php"页面中.通过单击"search.php"页面中的搜索按钮可以调用此功能.

I am making a function which searches the database for flight information. I want user to be redirected on "ticket.php" if the response is true. I want to update the content of the page "ticket.php" using jquery. But jquery doesn't work. Am I doing something wrong here ? Here's part of javascript. It's an external javascript. It's included in both "search.php" and "ticket.php" page. This function gets invoked by clicking on search button in "search.php" page.

if(data){
    setTimeout("location.href = 'ticket.php';",3000); // Redirect to new page

//Change content of "ticket.php" using jquery.
    $("#source").text(x);
    $("#destination").text(y);
    $("#date").text(z);
    $("#no_person").text(person);
    $("#trip_type").text(type);
}

else
    $("#alert").text("Oops! No Flight matches your criteria ! ");

推荐答案

将location.href设置为ticket.php时,用户将被重定向到该新页面(ticket.php).然后,浏览器将加载该新页面,并且将不再使用当前页面上的JavaScript.

When you set location.href to ticket.php, the user is then redirected to that new page (ticket.php). Then the browser will load that new page and will no longer use the javascript you have on your current page.

您将必须使用例如使数据显示在ticket.php上.从他们搜索的内容中获取的url参数是这样的:

You will have to make the data appear on ticket.php, using e.g. url parameters taken from what they searched like this:

window.location.href = 'ticket.php?from=norway&to=sweden';

这篇关于有什么方法可以重定向到新页面并在该页面上使用jquery编写一些内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆