2011-10-31 61 views
0

我想用一些jQuery代码到:如何使用jQuery打开新页面?

a) Watch for when an element #RetrieveData is clicked 
b) Get the value of #DataSource and put this into xxx 
c) Open up a new page with url "/person/ds=xxx 

我已经做了Ajax调用类似,但从来没有打电话来了新的一页的东西。有人可以给我一些建议,我该如何做到这一点?

+0

可以重新使用,你必须使用Ajax这样做的代码调用 - 使它打开一个新页面,而不是使用['location']是微不足道的(https://developer.mozilla.org /en/DOM/window.location) –

回答

3
$('#RetrieveData').click(function() { 
    var xxx = $('#DataSource').val(); 
    window.location.href = '/person?ds=' + encodeURIComponent(xxx); 
    return false; 
}); 
+0

感谢您的好例子 –

0

当你写“新页面”,你的意思是一个新的窗口或只是页面重定向?

http://jsfiddle.net/DTG7G/5/

$('#RetrieveData').click(function(e) { 
    e.preventDefault(); 
    var xxx = $('#DataSource').val(); 

    //open in new window 
    //window.open('/person?ds=' + encodeURIComponent(xxx)); 

    //open in same window 
    window.location.href = '/person?ds=' + encodeURIComponent(xxx); 
});