【发布时间】:2011-05-20 13:41:05
【问题描述】:
我查看了其他一些问题,但我仍然不确定如何实现这一目标。
情况是我有一个复杂的表单,它静态工作得很好,但我通过使用 AJAX 请求提交它来“让它变得更好”。
现在页面的 url 并没有像以前那样更改为包含参数,但我可以使用 firebug 看到完全限定的 url。
我的目标是获取这个网址并制作一个链接到它的按钮,以便用户可以将其添加为书签,因为目前无法为搜索结果添加书签。
很抱歉,如果这是完全重复的,但非常感谢任何帮助和建议。
这是我的 AJAX 请求(它们基本相同,但我有两个表单作为一个表单呈现给用户,一个简单搜索和一个切换的高级搜索):
// setup AJAX request for simple search
$simpleform = $('#search');
$simpleform.submit(function() {
$.ajax($simpleform.attr('action'), {
data: $simpleform.serialize(),
dataType: 'html',
url: 'docsearch.php',
type: 'GET',
beforeSend: function() {
var $load = $('#loadingmessage');
$('#search_results').fadeOut(1000);
$load.hide().fadeIn(1000);
if (!$load.length)
{
$load = $('<div id="loadingmessage">').appendTo($('#placeholder'));
}
$load.html('Searching... Please wait...');
// disable both search buttons
$('.submit').attr('disabled', 'disabled');
$('.submit').addClass("disabled");
$('#advancedsearchbutton').attr('disabled', 'disabled');
$('#advancedsearchbutton').addClass("disabled");
},
success: function(response) {
// response is the text sent back by server
// find the search_results div in the response and insert it after the placeholder div
$(response).find('#search_results').insertAfter($('#placeholder')).fadeIn(1000);
// re-initialise lightbox and dataTable plugins
$('a.lightbox').lightBox();
$('#test-docs-table').dataTable( {
"sPaginationType": "full_numbers",
"sDom": 'Rlfrtip',
"aoColumns": [
null,
null,
{ "sType": "title-numeric" },
null
]
});
},
complete: function() {
// hide loading message:
$('#loadingmessage').fadeOut('slow');
// enable both search buttons
$('.submit').removeAttr("disabled");
$('.submit').removeClass("disabled");
checkDropdowns();
}
});
return false; // Cancel default event
});
// end AJAX request
// setup AJAX request for advanced search
$form = $('#advancedsearchform');
$form.submit(function() {
$.ajax($form.attr('action'), {
data: $form.serialize(),
dataType: 'html',
url: 'docsearch.php',
type: 'GET',
beforeSend: function() {
var $load = $('#loadingmessage');
$('#search_results').fadeOut(1000);
$load.hide().fadeIn(1000);
if (!$load.length)
{
$load = $('<div id="loadingmessage">').appendTo($('#placeholder'));
}
$load.html('Searching... Please wait...');
// disable both search buttons
$('.submit').attr('disabled', 'disabled');
$('.submit').addClass("disabled");
$('#advancedsearchbutton').attr('disabled', 'disabled');
$('#advancedsearchbutton').addClass("disabled");
},
success: function(response) {
// response is the text sent back by server
// find the search_results div in the response and insert it after the placeholder div
$(response).find('#search_results').insertAfter($('#placeholder')).fadeIn(1000);
// re-initialise lightbox and dataTable plugins
$('a.lightbox').lightBox();
$('#test-docs-table').dataTable( {
"sPaginationType": "full_numbers",
"sDom": 'Rlfrtip',
"aoColumns": [
null,
null,
{ "sType": "title-numeric" },
null
]
});
},
complete: function() {
// hide loading message:
$('#loadingmessage').fadeOut('slow');
// enable both search buttons
$('.submit').removeAttr("disabled");
$('.submit').removeClass("disabled");
$('#advancedsearchbutton').removeAttr("disabled");
$('#advancedsearchbutton').removeClass("disabled");
}
});
return false; // Cancel default event
});
// end AJAX request
【问题讨论】: