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 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键