2015-03-13 75 views
0

我想打开一个新页面,只要用户点击我的一个使用JQuery的html选项选项。在JQuery教程的示例之后,我构建了如下所示的代码。然而,当我点击任何一个选项使用jQuery打开一个新的php页面

$('#Databases').change(function() { 

    $.post("test.php"); 
}); 

哪里Databases是我SELECTID的页面无法打开。为什么我不能打开test.php?有解决方案吗?

+0

'$ .POST()'使得一个AJAX请求。如果你想改变当前页面,你需要[适当地设置'window.location'](https://developer.mozilla.org/en-US/docs/Web/API/Window/location)。 – Phylogenesis 2015-03-13 09:14:38

回答

1

您应该使用window.locationwindow.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 
}); 
1

使用window.open功能:

$('#Databases').change(function() { 
    window.open("test.php"); 
}); 

因为$.post只是$.ajaxtype='post' - 异步调用。您可以在该功能的donesuccess部分打开新窗口,但我想这不是您想要的。

+0

感谢您的快速回复。 – b0w3rb0w3r 2015-03-13 09:28:44

3

open()方法打开一个新的浏览器窗口。 如果你想在同一浏览器窗口中打开新页面,我建议使用window.location.assign()

实施例:

$('#Databases').change(function() { 
    window.location.assign("test.php"); 
}); 

Reference

相关问题