【问题标题】:Why is this json script not working in IE7 & 8, but works in all other browsers?为什么这个 json 脚本在 IE7 和 8 中不起作用,但在所有其他浏览器中都起作用?
【发布时间】:2012-04-23 08:39:29
【问题描述】:

我的网站重建工作差不多完成了,现在正处于测试阶段。在 IE7 和 8 中进行测试时,我发现由于 json 脚本,我的 jquery 脚本无法正常工作,即使它们在包括 IE9 在内的所有其他浏览器中都可以正常工作。

页面为:http://www.carcityofdanbury.com/New/?cat=01&do=View&stock=18481

脚本是信息请求表,在这一行: ".append("<p>Thank you " + data.name + ",</p><p class=\"indent\">we recieved your info request " + data.for + " on our<br />'.$vehicle.' and will contact you shortly.</p>")" 导致 jquery 选项卡不再工作。

我做了 php 和 jquery 编码,但是雇了人来做 json,所以我不知道如何解决这个问题。有什么想法吗?

【问题讨论】:

  • 雇人做JSON?
  • “信息请求”表单由其他人完成

标签: jquery json


【解决方案1】:

解决了...代码中多了一个逗号:

        <script language="javascript" type="text/javascript">
        $(document).ready(function() {

        // Tabs
            $("#tabs").tabs();

        // Google map
            $(\'#embed\').gmap3(
                {action: \'addMarker\', lat:41.40372, lng:-73.45844, map:{center: true, zoom: 17, mapTypeId: google.maps.MapTypeId.ROADMAP}}
            );

        // Pic popup
            $("#viewPics").fancybox({
                \'type\': \'iframe\', \'transitionIn\': \'fade\', \'transitionOut\': \'fade\', \'width\': 900, \'height\': 500, \'autoScale\': false, \'scrolling\': \'no\'
            });

        // Form Validation
            jQuery.validator.messages.required = "";
            $("#infoForm").validate({

                invalidHandler: function(e, validator) {
                    var errors = validator.numberOfInvalids();
                    if (errors) {
                        var message = errors == 1
                            ? \'You missed 1 required field.\'
                            : \'You missed \' + errors + \' required fields\';
                        $("li.Error span").html(message);
                        $("li.Error").show();
                    } else {
                        $("li.Error").hide();
                    }
                },

                onkeyup: false,
                submitHandler: function(form) {
                    $.ajax({
                        url: "01/Resources/infoRequest.php",
                        type: "POST",
                        cache:false,
                        data: $("#infoForm").serialize(),
                        dataType: "json",
                        success: function(data) {
                            $("li.Error").hide();
                            $("#contact_form").html(\'<div id="message"></div>\');
                            $("#message").html("<h2>Info Request Submitted!</h2>")
                            .append("<p>Thank you " + data.name + ",</p><p class=\"indent\">we recieved your info request " + data.test + " on our<br />'.$vehicle.' and will contact you shortly.</p>")
                            .hide()
                            .fadeIn(2500, function() {
                                $("#message").append("<p>Would you like to <a href=\"?cat=02&stock='.$stock.'\">prefill an application</a> now?</p>")
                            });
                        }
                    });
                }, <------- This guy was the culprit

            });

        });
    </script>

【讨论】:

    【解决方案2】:

    问题出在data.for 上,听起来有点像您(编写代码的人)正在尝试访问其中一个保留名称。即使data.for 应该是有效的,IE 也不喜欢它认为特殊的名称(例如类)。 data.class 会导致 IE 出现问题,即使它是有效的。

    例如,尝试将 data.for 重命名为其他名称 data._for。确保更新 01/Resources/infoRequest.php PHP 文件以返回 new 值。

    【讨论】:

    • 我将 data.for 更改为 data.test 并没有解决问题。
    • 您还需要更新01/Resources/infoRequest.php。从 AJAX 调用返回的数据仍然引用 for,所以它现在显示为 ...we recieved your info request undefined on our...。不过,我在 IE 中看不到原来的错误。
    • 这太奇怪了,因为它解决了 IE8 的问题,但仍然没有解决 IE7。
    • 或者,尝试访问data['for'] 而不是data.for
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 2011-07-22
    • 2013-06-10
    • 2014-08-13
    相关资源
    最近更新 更多