【发布时间】:2016-09-07 11:23:48
【问题描述】:
我正在使用三层架构并尝试使用 jquery ajax 将数据存储到数据库中,但在成功函数中没有得到响应
这是我的代码
portalDAL.cs
public DataTable InsertFeedBack(String Name, String Email, string Category, string Message)
{
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter("@Name",Name),
new SqlParameter("@Email",Email),
new SqlParameter("@Category",Category),
new SqlParameter("@Message",Message)
};
return Helper.ExecuteParamerizedSelectCommand("insert into feedback(name,email,category,message) values(@Name,@Email,@Category,@Message)", CommandType.Text, parms);
}
portalBAL.cs
public DataTable InsertFeedBack(String Name, String Email, string Category, string Message)
{
return portalDAL.InsertFeedBack(Name, Email, Category, Message);
}
portal.asmx.cs
[WebMethod]
public String InsertFeedBack(String Name, String Email, string Category, string Message)
{
DataTable dt = detailsBAL.InsertFeedBack(Name, Email, Category, Message);
return JsonConvert.SerializeObject(dt);
}
我的 Jquery 函数。
$(document).ready(function () {
$('#submit').click(function () {
var name = $('#name').val();
var email = $('#email').val();
var category = $('#cate').val();
var msg = $('#msg').val();
insertFeedback(name,email,category,msg);
});
function insertFeedback(name,email,cat,msg)
{
$.ajax({
type: "POST",
url: "portal.asmx/InsertFeedBack",
data: "{'Name':'" + name + "','Email':'" + email + "','Category':'" + cat + "','Message':'" + msg + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("hi");
var obj = data.d;
if (obj == 'true') {
$('#name').val('');
$('#email').val('');
$('#cate').val('');
$('#msg').val('');
$('#lblmsg1').html("Details Submitted Successfully");
window.location.reload();
}
},
error: function (result) {
alert("Error");
}
});
}
});
我收到错误警报消息控件没有进入成功功能它没有在浏览器上显示任何错误
【问题讨论】:
-
您是否在 firebug 控制台中检查过服务器出现了什么错误?如果是,您可以发布错误消息或错误文本的屏幕截图吗?
-
它在控制台上没有显示任何错误..收到错误消息警报后将能够在控制台上看到此错误“未捕获的异常无法转换为字符串”
-
有一些服务器端错误。在您的 Web 方法上放置一个调试点并检查它在哪里出现此错误。
-
你的意思是你不能调用你的服务器端方法吗?所以如果你的 web 方法中有一个断点,然后通过 ajax 调用它,断点不会命中?