$.ajax() 不适用于 Firefox 以外的任何浏览器

发布于 2024-10-07 22:27:13 字数 2471 浏览 0 评论 0 原文

我有一个小脚本,可以在页面加载时检索租赁日期,如果用户从下拉列表中选择另一个月份,还可以检索新日期。

该网站使用的是 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 中有效?有没有更简单的方法来做到这一点?

I have a small script which retrieves rental dates when the page loads, and also retrieves new dates if the user picks another month from the drop down.

The site is using jQuery 1.2.3 and I am stuck with that for now (legacy scripts) so I can't update to 1.4.

I wrote and debugged this in Firefox with Firebug, and realized that it doesn't work in any other browser. I am not sure why. In Firefox, I definitely get new dates and the div updates itself with the received AJAX data. Other browsers don't do anything.

$(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>

Why does this only work in Firefox? Is there an easier way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染年凉城似染瑾 2024-10-14 22:27:13

我敢打赌这是 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.

若水般的淡然安静女子 2024-10-14 22:27:13

您可以尝试为您的代码运行最新版本的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文