2011-02-09 66 views
1

我這樣做:使人們看到查詢字符串

$.ajax({ 
    type: 'GET', 
    url: this.href, 
    async: true, 
    data: $('form').first().serialize(), 
    beforeSend: function() { 
    $.blockUI({ message: 'Please wait ...' }); 
    }, 
    complete: function() { 
    $.unblockUI(); 
    }, 
    success: function(result) { 
    $("#grid").replaceWith($("#grid", result)); 
    }, 
    dataType: "text" 
}); 

是否有可能從展示的形式獲得,使用戶可以存儲鏈接查詢字符串?

謝謝。

基督教

回答

4

當然,只是預先計算的序列化形式:

var the_data = $('form').first().serialize(); 
$.ajax({ 
    type  : 'GET', 
    url  : this.href, 
    async  : true, 
    data  : the_data, 
    beforeSend: function() { 
     $.blockUI({ message: 'Please wait ...' }); 
    }, 
    complete : function() { 
     $.unblockUI(); 
    }, 
    success : function(result) { 
     $("#grid").replaceWith($("#grid", result)); 

     // Based on your comment, I am alerting `the data` to clarify 
     // the example. Obviously you'll want to display this on the page 
     // rather than using an alert. 
     alert(the_data); 
    }, 
    dataType : "text" 
}); 
+0

似乎沒有任何區別。 – cs0815 2011-02-09 15:56:31

0

$('form').first().serialize()只要保存爲一個變量。

var query = $('form').first().serialize(); 
$.ajax({ 
    type: 'GET', 
    url: this.href, 
    data: query, 
    ... 
    success: function(result){ 
     //you can use query in here... 
    } 
    ... 
});