提交表单后出错

时间:2011-08-30 15:51:11

标签: javascript jquery ajax forms

Form_Ajax.php =>

<script type="text/javascript" src="Testing_Ajax.js"></script>

<script type="text/javascript" src="jquery-1.5.js"></script>

<script type="text/javascript" src="myjquery.js"></script>

<style>

    .cls_display{

        background-color: green;

    }

</style>



<form name="nm_form" method="POST" action="Display_Ajax.php">

    <table>     

        <tr><td>User Name:</td><td><input type="text" name="nm_username" id="id_username"/></td></tr>

        <tr><td>Password:</td><td><input type="text" name="nm_password" id="id_password"/></td></tr>

        <tr><td><input type="button" value="Submitrunajax" onclick="runAjax()"/></td></tr>

        <tr><td><input type="button" class="cls_post" value="Submitjqueryajax"/></td></tr>

        <tr><td><input type="submit" class="cls_post" value="SubmitPOST"/></td></tr>

    </table>

    <div id="id_display" class="cls_display">



    </div>

</form>

Display_Ajax.php =&gt;

<?php



class Display_Ajax{

    public function __construct(){



    }

    public function printall(){

        $var_username=$_POST["nm_username"];

        $var_password=$_POST["nm_password"];

        echo $var_username.'<br>';

        echo $var_password.'<br>';

    }

}



$var_obj=new Display_Ajax();

$var_obj->printall();

?>

myjquery.js =&gt;

$(document).ready(function(){

    $("div").addClass('cls_display');



    $("input.cls_post").click(function(){

        var temp1,temp2;

        temp1=$("#id_username").val();

        temp2=$("#id_password").val();

        /*

        $.post("Display_Ajax.php",{nm_username: temp1, nm_password: temp2},function(prm){

            alert(prm);

            $("div.cls_display").html(prm);

        });

        */

        $.ajax({

            type: "POST",

            url: "Display_Ajax.php",

            data: "nm_username="+temp1+"&"+"nm_password="+temp2,

            success: function(prm){

                alert(prm);

                $("div.cls_display").html(prm);

            }

        });     



    });



});

http://localhost/Form_Ajax.php,点击第三个提交按钮我就得到了值。

<tr><td><input type="submit" class="cls_post" value="SubmitPOST"/></td></tr>

但是从Firefox&gt;工具&gt;错误控制台我得到错误=&gt;

Firebug's log limit has been reached. 0 entries not shown.      Preferences  
uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.getAllResponseHeaders]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://localhost/jquery-1.5.js :: anonymous :: line 7207" data: no]

1 个答案:

答案 0 :(得分:0)

尝试更改您的数据区域:

data:"nm_username="+temp1+"&"+"nm_password="+temp2

为:

data: {nm_username : temp1,nm_password : temp2},

看看是否有效。

在此页面上阅读:http://api.jquery.com/jQuery.ajax/