使用jquey.ajax时出错 [英] Error in using jquey.ajax
本文介绍了使用jquey.ajax时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
我在asp.net应用程序中使用jquery 1.6.2.每当我尝试使用jquery.ajax()更新数据库时,都会显示以下错误.
回应:[object:object]
状态:parseerror
文本:语法错误:语法错误
这是我的jquery代码.
Hello firends,
I''m using jquery 1.6.2 in my asp.net application. every time when I''m trying to update my database using jquery.ajax() it shows me the following error.
Response:[object:object]
Status: parseerror
Text: Syntax Error: Syntax Error
This is my jquery code.
var val = $("#dpRating").val();
$.ajax({
type: "POST",
url: "Media.aspx/UpdatemMethod",
data: "{value:" + val + "}",
contentType: "application/json",
dataType: "json",
success: function(data) {
alert(data.d);
$("#lblMsg").text("Updated");
},
error: function(response, status, text) {
alert("Error \n Response:" + response + "\n Status:" + status + "\n Text:" + text);
}
});
HTML代码
Html Code
<asp:DropDownList ID="dpRating" runat="server">
<asp:ListItem Value="0" Text="0"></asp:ListItem>
<asp:ListItem Value="1" Text="1"></asp:ListItem>
<asp:ListItem Value="2" Text="2"></asp:ListItem>
<asp:ListItem Value="3" Text="3"></asp:ListItem>
<asp:ListItem Value="4" Text="4"></asp:ListItem>
<asp:ListItem Value="5" Text="5"></asp:ListItem>
<asp:ListItem Value="6" Text="6"></asp:ListItem>
<asp:ListItem Value="7" Text="7"></asp:ListItem>
<asp:ListItem Value="8" Text="8"></asp:ListItem>
<asp:ListItem Value="9" Text="9"></asp:ListItem>
<asp:ListItem Value="10" Text="10"></asp:ListItem>
</asp:DropDownList>
<input type="button" value="Submit" onclick="UpdateRating()" />
我的C#代码
My C# Code
[System.Web.Services.WebMethod]
public static string UpdateMethod(string value)
{
string res = "Entered";
string query = string.Empty;
if (id != null && !string.IsNullOrEmpty(area))
{
Media m = new Media();
if (area == "Headers")
{
query = "UPDATE mytable1 SET pro=''" + value + "'' WHERE Id=''" + id+"''";
}
if (area == "Contents")
{
query = "UPDATE mytable2 SET pro=''" + value + "'' WHERE id=''" + id+"''";
}
if (!string.IsNullOrEmpty(query))
{
m.doQuery("",query,1);
res = "Done";
}
}
return res;
}
请指导我
Please guide me
Thanks.
推荐答案
(#dpRating").val();
("#dpRating").val();
.ajax({ 输入:"POST", 网址:"Media.aspx/UpdatemMethod", 数据:"{value:" + val +}", contentType:"application/json", dataType:"json", 成功:功能(数据){ alert(data.d);
.ajax({ type: "POST", url: "Media.aspx/UpdatemMethod", data: "{value:" + val + "}", contentType: "application/json", dataType: "json", success: function(data) { alert(data.d);
(#lblMsg").text("Updated"); }, 错误:功能(响应,状态,文本){ alert(错误\ n响应:" +响应+"\ n状态:" +状态+"\ n文本:" +文本); } });
("#lblMsg").text("Updated"); }, error: function(response, status, text) { alert("Error \n Response:" + response + "\n Status:" + status + "\n Text:" + text); } });
HTML代码
Html Code
<asp:DropDownList ID="dpRating" runat="server">
<asp:ListItem Value="0" Text="0"></asp:ListItem>
<asp:ListItem Value="1" Text="1"></asp:ListItem>
<asp:ListItem Value="2" Text="2"></asp:ListItem>
<asp:ListItem Value="3" Text="3"></asp:ListItem>
<asp:ListItem Value="4" Text="4"></asp:ListItem>
<asp:ListItem Value="5" Text="5"></asp:ListItem>
<asp:ListItem Value="6" Text="6"></asp:ListItem>
<asp:ListItem Value="7" Text="7"></asp:ListItem>
<asp:ListItem Value="8" Text="8"></asp:ListItem>
<asp:ListItem Value="9" Text="9"></asp:ListItem>
<asp:ListItem Value="10" Text="10"></asp:ListItem>
</asp:DropDownList>
<input type="button" value="Submit" onclick="UpdateRating()" />
我的C#代码
My C# Code
[System.Web.Services.WebMethod]
public static string UpdateMethod(string value)
{
string res = "Entered";
string query = string.Empty;
if (id != null && !string.IsNullOrEmpty(area))
{
Media m = new Media();
if (area == "Headers")
{
query = "UPDATE mytable1 SET pro=''" + value + "'' WHERE Id=''" + id+"''";
}
if (area == "Contents")
{
query = "UPDATE mytable2 SET pro=''" + value + "'' WHERE id=''" + id+"''";
}
if (!string.IsNullOrEmpty(query))
{
m.doQuery("",query,1);
res = "Done";
}
}
return res;
}
请指导我
谢谢.
Please guide me
Thanks.
这篇关于使用jquey.ajax时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文