Gre*_*g B 0 forms ajax jquery load
我确定我在这里做了很多错误,但具体来说,我正试图从表单中提取一些信息并将其组合成一个我可以接受的URL.load():
$(document).ready(function() {
origin = $('#origin').val();
destination = $('#destination').val();
weekDay = $('#weekday').val();
fullSchedule = origin+'_'+destination+'_'+weekDay+'.html';
$("#scheduleform :submit").click(function() {
$('#schedule').load(fullSchedule);
alert( fullSchedule );
});
});
Run Code Online (Sandbox Code Playgroud)
我可以提醒完整的URL,但我似乎无法将其加载到div(具有日程安排的ID).
我基本上把我所知道的小jquery一起蹒跚而行,所以我确定它很乱,但我不确定为什么它会正常警告但不加载div.
如果您有Firebug,您是否可以验证请求是否发送到服务器并且您收到了响应?还尝试将回调放入load以查看加载是否成功完成:
$('#schedule').load(fullSchedule, function(responseText, textStatus, XMLHttpRequest) {
alert("Load result: " + responseText + " " + textStatus);
});
Run Code Online (Sandbox Code Playgroud)
其他一些事情:
我注意到了另外一件事.你有什么理由click()而不是用submit()?所以:
$("#scheduleform").submit(function() {
...
return false; //You probably don't want the page to actually submit and reload
});
Run Code Online (Sandbox Code Playgroud)
绕过整个提交业务的另一种方法就是使用一个不是提交按钮的标准按钮,然后绑定click它(取决于你当然在做什么 - 我不知道你是否真的想要提交任何东西).