该变量应该在单击提交按钮时插入,但不起作用。我认为这可能是我如何调用ajax代码的问题。请帮帮我
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0-beta.1/jquery.mobile-1.3.0-beta.1.min.js"></script>
<div id="additem" data-role="page" data-theme="b">
<div data-role="header">
<h1>Add Item</h1>
</div>
<div data-role="content">
<form name="form1" method="post" action="">
<table width="195" border="0" cellpadding="3" cellspacing="3">
<tr>
<td><p> <strong>Item Name</strong></td>
</tr>
<tr>
<td><input name="item_name" type="text" id="item_name" onFocus="if(this.value=='Item Name')this.value=''" onBlur="if(this.value=='')this.value='Item Name'" value="Item Name"></td>
</tr>
<tr>
<td><p> <strong>Quantity</strong></p></td>
</tr>
<tr>
<td><input name="quantity" type="text" id="quantity" size="5"></td>
</tr>
<tr>
<td><strong>Price</strong></td>
</tr>
<tr>
<td><p>
<input name="price" type="text" id="price" size="5">
</p></td>
</tr>
<tr>
<td>
<input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</div>
<div data-role="footer">
<h4>Footer</h4>
</div>
</div>
<script>
$(document).ready(function(){
$("form").on('submit',function(event){
event.preventDefault();
data = $(this).serialize();
$.ajax({
type: "POST",
url: "item_add.asp",
data: data
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
});
});
</script>
插入脚本:
<!--#include file="Connections/shop_app.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%>
<%
If (CStr(Request("MM_insert")) = "form1") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_shop_app_STRING
MM_editCmd.CommandText = "INSERT INTO Item_Table (Q_Item, Quantity, Selling_Price) VALUES (?, ?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 200, Request.Form("item_name")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("quantity"), Request.Form("quantity"), null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("price"), Request.Form("price"), null)) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
End If
%>
当我点击提交按钮时,会出现错误,说明错误加载页面