我试图提交一个带有ajax的表单,但我得到NS_ERROR_XPC_BAD_CONVERT_JS:无法转换JavaScript参数

时间:2013-02-23 09:17:18

标签: php ajax

这是包含正在提交的表单的页面。我主演了具有

形式的代码
<html>

<head> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
   <script src="Scripts/homepage.js"></script>

<link rel='stylesheet' href='index.css'> 


</head>

<body>

<img src="wc.png" id="wc">

<div id="banner"> <h1> Wolfeboro Connection </h1> </div>

<div id="feed"> <iframe src="feed.html" id="iframefeed"> </iframe> </div>

<div id="footer"> </div>


<div id="accounts">   <table> <tr> <th> Sign In </th> </tr>
<tr> <td> Username </td> <td>  <input type="text" name="loginusername"> </td> </tr>
<tr> <td> Password </td> <td> <input type="password" id="loginpassword"> </td> </tr>
<tr> <td> </td> <td> <input type="submit" value="submit"> </td> </tr>


</table>

**<table>
<tr> <th>Sign Up </th> </tr>  
<tr> <td>Restaurant Name </td> <td>  <input type="text" id="signupusername"> </td> </tr>
<tr> <td> Password </td> <td> <input type="password" id="verifypassword"> </td> </tr>
<tr> <td> Verify Password </td> <td> <input type="password" id="signuppassword"> 
</td> </tr> 
<tr> <td> Phone Number </td> <td> <input type="text" id="phoneNumber"> </td> </tr>
<tr> <td> Email </td> <td>  <input type="text" id="email"> </td> </tr>
<tr> <td> </td> <td> <input type="button" value="submit" id="signupsubmit"> </td> </tr>
</table>**

</div>


</body>

</html>

这是我试图用

提交表单的ajax
$(function () {


$("#signupsubmit").click(function() {

$.ajax({
type: "POST",
url: "signup.php",
data: { name: signupusername, password: signuppassword , phonenumber: phoneNumber ,    
email: email }
});

});

});

这是带有php的页面

 <?php


    $db = new mysqli('localhost', 'root', 'brewster01', 'WolfeboroConnection');



    $stmt = $db->stmt_init();

    if($stmt->prepare("INSERT INTO users 
    (BusinessName, Password, Phone, Email) VALUES (?,?, ?, ?)")) {

    $stmt->execute();
    $stmt->close();

    }
    else
    {
    error_log(mysqli_error($db));
    }


?> 

[04:16:51.977] NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument @ http://code.jquery.com/jquery-1.9.1.min.js:5

1 个答案:

答案 0 :(得分:0)

输入元素不会自动转换为变量,您必须使用方法获取它们的值。

$.ajax({
    type: "POST",
    url: "signup.php",
    data: { name: $("#signupusername").val(), 
            password: $("#signuppassword").val(),
            phonenumber: $("#phoneNumber").val(),    
            email: $("#email").val()
    }
});

在PHP中,准备语句后,您需要执行以下操作:

$stmt->bind_param('ssss', $_POST['name'], $_POST['password'], $_POST['phonenumber'], $_POST['email']);