dop83362 2010-11-24 22:24
浏览 114
已采纳

为什么这个Jquery Ajax不能在Opera和Safari中运行?

This code works in FF, Chrome, IE6/8 but not in Safari and Opera. Any ideas why?

Here is the code:

var name = $('#esm').val();
        var email = $('#nam').val();
        var message = $('#med').val();
        var ad_id = $('#i_d').val();

    var data_string = 'esm='+ name + '&nam=' + email + '&med=' + message + '&i_d=' + ad_id;

            $.ajax({
                type:       "POST",
                url:        "/my_php_file.php",
                data:       data_string,
                success:    function(data) {
                    $('#tip_loader').hide();
               if(data==1){alert('success'); }
               else {alert('error'); }
                       }//end success function
        }) //end ajax call

I have located the error to exactly the "Ajax" call, because when I put an alertbox just before the $.ajax the alert shows up correctly. However, if I put the alertbox in the success function, nothing shows up, no alert.

This only happens in Opera and Safari...

EDIT:

FYI: I include this javascript file into a php file, and I also include the jquery.js file into the php file. So this is all in an external file.

EDIT:

/main.php /bin/jquery.js /bin/tip.js /bin/tip.php

I include the above js files into main.php, and the form action in main.php is set to /bin/tip.php

And the path to the ajax url is /bin/tip.php instead of my_php_file.php

  • 写回答

3条回答 默认 最新

  • duanche5149 2010-11-24 22:44
    关注

    Opera has a debugging tool built in called Dragonfly. Go to the Tools menu -> Advanced ->Opera Dragonfly
    If you don't have the File menu bar, click Menu -> Page -> Developer Tools -> Open Opera Dragonfly

    Once you have it open (open it on the page that you're working on), click the Scripts tab (it'll probably ask you to refresh the page, do that) and drop down to your external js file. Once you've found your code, you can set a breakpoint on the $.ajax() line by clicking on the line number on the left side. Now, trigger your code and you'll see that it will break on that JavaScript line. You can then use the inspection tab (bottom, middle) to ensure that all of your variables are set correctly. You can also step through and debug the JavaScript.

    The other thing you'll want to do is add an error function like so:

    $.ajax({
        type: "POST",
        url: "/my_php_file.php",
        data: data_string,
        success: function(data) {
            $('#tip_loader').hide();
            if (data == 1) { alert('success'); }
            else { alert('error'); }
        }, //end success function
        error: function(xhr, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });  //end ajax call
    

    See if that gives you any more information.

    Also, check the error console as @Mufasa suggested. It can be found under the Error Console tab in Dragonfly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器