代码之家  ›  专栏  ›  技术社区  ›  ayush

jquery ajax请求firebug错误

  •  1
  • ayush  · 技术社区  · 14 年前

    优惠券.js

    jQuery(document).ready(function(){
            jQuery(".appnitro").submit( function(e) {
    $.ajax({
                url     : "http://174.132.194.155/~kunal17/devbuzzr/wp-content/themes/street/sms.php",
                type    : "post",
                dataType: "json",
                data    : $(this).serialize(),
                success : function( data ) {
                            for(var id in data) {
                                jQuery('#' + id).html( data[id] );
                            }
                          }
    
            });
    //return false or
    e.preventDefault();
    
        });
    
    });
    

    短信.php

        <?php
        //process form
    $res = "Message successfully delivered";
        $arr = array( 'mess' => $res );
        echo json_encode( $arr );//end sms processing
        unset ($_POST);
        ?>
    

    这是我的html页面的代码-

    <form id="smsform" class="appnitro" action="http://174.132.194.155/~kunal17/devbuzzr/wp-content/themes/street/sms.php" method="post">
    ...
    </form>
    <div id="mess" style="background:green;"></div>
    

    现在当我点击submit按钮时,什么也没有发生,firebug在控制台面板下显示如下内容-

    POST http://174.132.194.155/~kunal17/devbuzzr/wp-content/themes/street/sms.php
    
    404 Not Found 1.29s   `jquery.min.js (line 130)`
    
    Response
    
    Firebug needs to POST to the server to get this information for url:
    http://174.132.194.155/~kunal17/devbuzzr/wp-content/themes/street/sms.php
    
    This second POST can interfere with some sites. If you want to send the POST again, open a new tab in Firefox, use URL 'about:config', set boolean value 'extensions.firebug.allowDoublePost' to true
    This value is reset every time you restart Firefox This problem will disappear when https://bugzilla.mozilla.org/show_bug.cgi?id=430155 is shipped
    

    POST http://174.132.194.155/~kunal17/devbuzzr/wp-content/themes/street/sms.php
    
    404 Not Found 1.29s   `jquery.min.js (line 130)`
    
    Response - 
    
    {"mess":"Message successfully delivered"}
    

    jquery.min.js (line 130) 在旁边?

    别担心 http://174.132.194.155/~kunal17/devbuzzr/wp-content/themes/street 这是我的基本网址

    2 回复  |  直到 14 年前
        1
  •  0
  •   T.P.    14 年前

    编辑:

    我的x.html,对应于你的html页面

    
    <!DOCTYPE html>
    <html>
    <head>
    <title>x</title>
    <script 
      type="text/javascript" 
      src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
    </script>
    <script type="text/javascript" src="/so/x.js"></script>
    </head>
    <body>
    <form id="smsform" class="appnitro" action="/so/x.php">
    <input type="text" name="zz">
    <input type="submit">
    </form>
    <div id="mess" style="background:green;"></div>
    </body>
    </html>
    
    

    我的x.js与你的优惠券.js

    
    jQuery(document).ready(function(){
      jQuery(".appnitro").submit( function(e) {
        e.preventDefault();
        $.ajax({
          url     : "/so/x.php",
          type    : "post",
          dataType: "json",
          data    : $(this).serialize(),
          success : function( data ) {
            for(var id in data) {
              jQuery('#' + id).html( data[id] );
            }
          }
    
        });
        //return false or
        //e.preventDefault();
      });
    });
    

    
    <?php
    $res = "Message successfully delivered.";
    $arr = array('mess'=>$res);
    echo json_encode($arr);
    unset($_POST);
    ?>
    

    这实际上可以在我的环境中工作,尽管我没有剩余的HTML标记或额外的PHP表单处理代码。“消息已成功传递。”在输入字段的正下方显示为绿色。

        2
  •  0
  •   Liam Bailey    14 年前

    在Ajax调用中,这指的是需要执行此操作的Ajax对象

    var __this = this; 
    

    在进入Ajax调用之前

    data    : __this.serialize()
    

    或者在Google的Ajax调用中查找上下文的使用。或者在进入Ajax调用之前将数据序列化为变量。