$.ajax() 不适用于 Firefox 以外的任何浏览器
我有一个小脚本,可以在页面加载时检索租赁日期,如果用户从下拉列表中选择另一个月份,还可以检索新日期。
该网站使用的是 jQuery 1.2.3,但我现在仍坚持使用该版本(旧脚本),因此无法更新到 1.4。
我用 Firebug 在 Firefox 中编写并调试了它,并意识到它在任何其他浏览器中都不起作用。我不知道为什么。在 Firefox 中,我肯定会得到新的日期,并且 div 使用接收到的 AJAX 数据自行更新。其他浏览器不执行任何操作。
$(document).ready(function() {
$.ajax({
url: '/rental/get_dates.cfm',
type: 'POST',
data: 'date=<cfoutput>#dateFormat(now(), "m-yyyy")#</cfoutput>&rental=<cfoutput>#val(getOneRental.rentalListingID)#</cfoutput>',
success: function(data) {
$('#rental_calendar .rentalRateData').html(data);
}
});
});
function update_calendar(date) {
$.ajax({
url: '/rental/get_dates.cfm',
type: 'POST',
data: 'date='+date+'&rental=<cfoutput>#val(getOneRental.rentalListingID)#</cfoutput>',
success: function(data) {
$('#rental_calendar .rentalRateData').html(data);
}
});
}
HTML:
<form name="rental_month" id="rental_month" method="post">
<select name="month">
<cfset month_choice = dateFormat(now(), 'm-yyyy')>
<cfoutput>
<option value="#lcase(month_choice)#" onclick="update_calendar('#month_choice#');" class="default">#dateFormat(month_choice, 'mmmm yyyy')#</option>
</cfoutput>
<cfloop from="1" to="12" index="i">
<cfset month_choice = dateFormat(dateAdd('m', i, now()), 'm-yyyy')>
<cfoutput>
<option value="#lcase(month_choice)#" onclick="update_calendar('#month_choice#');">#dateFormat(month_choice, 'mmmm yyyy')#</option>
</cfoutput>
</cfloop>
</select>
</form>
<div id="rental_calendar">
<table class="rentalRates" cellpadding="0" cellspacing="0" width="98%">
<tr>
<th align="left">Arrival</th>
<th align="right">Rate</th>
</tr>
</table>
<table class="rentalRateData" cellpadding="0" cellspacing="0" width="98%">
</table>
</div>
为什么这只在 Firefox 中有效?有没有更简单的方法来做到这一点?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我敢打赌这是 html() 函数。我会尝试警告数据以确保 ajax 函数正常工作,然后尝试使用不同的方式将数据添加到表中。
I bet it's the html() function. I'd try alerting the data to make sure the ajax functions are working, then try using a different way to add the data to your table.
您可以尝试为您的代码运行最新版本的 JQuery。以下是如何执行此操作的示例的链接:
http://www.comanswer.com/question/how-do-i-run- different-versions-of-jquery-on-the-same-page
You can try running the latest version of JQuery for your code. Here's an a link to an example of how to do this:
http://www.comanswer.com/question/how-do-i-run-different-versions-of-jquery-on-the-same-page