我想打开一个新页面,只要用户点击我的一个使用JQuery的html选项选项。在JQuery教程的示例之后,我构建了如下所示的代码。然而,当我点击任何一个选项使用jQuery打开一个新的php页面
$('#Databases').change(function() {
$.post("test.php");
});
哪里Databases
是我SELECTID的页面无法打开。为什么我不能打开test.php
?有解决方案吗?
我想打开一个新页面,只要用户点击我的一个使用JQuery的html选项选项。在JQuery教程的示例之后,我构建了如下所示的代码。然而,当我点击任何一个选项使用jQuery打开一个新的php页面
$('#Databases').change(function() {
$.post("test.php");
});
哪里Databases
是我SELECTID的页面无法打开。为什么我不能打开test.php
?有解决方案吗?
您应该使用window.location
或window.open
:
$('#Databases').change(function (e) {
window.open("testScript.php"); // if you want to open another window
// window.location.href = "testScript.php"; //if you want to open in same window
});
使用window.open功能:
$('#Databases').change(function() {
window.open("test.php");
});
因为$.post
只是$.ajax
与type='post'
- 异步调用。您可以在该功能的done
或success
部分打开新窗口,但我想这不是您想要的。
感谢您的快速回复。 – b0w3rb0w3r 2015-03-13 09:28:44
的open()
方法打开一个新的浏览器窗口。 如果你想在同一浏览器窗口中打开新页面,我建议使用window.location.assign()
。
实施例:
$('#Databases').change(function() {
window.location.assign("test.php");
});
'$ .POST()'使得一个AJAX请求。如果你想改变当前页面,你需要[适当地设置'window.location'](https://developer.mozilla.org/en-US/docs/Web/API/Window/location)。 – Phylogenesis 2015-03-13 09:14:38