<script type="text/javascript">
function fabu() {
var title = $("#shop_title").val();
var describe = $("#shopdescrib").val();
var type = $("#sel_type").val();
var addres = $("#shop_addres").val();
var price = $("#shop_price").val();
var pprice = $("#shop_pprice").val();
var shopname = $("#shop_pname").val();
var shopphone = $("#shop_phone").val();
var qq = $("#shop_QQ").val();
$.ajax({
type:"post",
url: "AddShop.aspx/Addshop",
datatype:"json",
data:{"title":title,"describe":describe,"type":type,"addres":addres,"price":price,"pprice":pprice,"shopname":shopname,"shopphone":shopphone,"qq":qq},
success:function(data){
if(data.d=="1"){
alert("成功");
}
else{
alert("失败"); //在后台断点的时候,不能进入到后台的断点部分,但是请求完数据后,执行的是这个语句
}
}
});
}
</script>
[WebMethod]
public static string Addshop(string title,string decribe,string type,string address,string price,string pprice,string shopname,string shopphone,string qq)
{
BLL.Tb_Shop bsp = new BLL.Tb_Shop(); //在这里断点
Model.Tb_Shop msp = new Model.Tb_Shop();
msp.Shop_Title = title;
msp.Shop_Describle = decribe;
msp.Shop_Type = type;
msp.Shop_Link = address;
msp.Shop_Price = Convert.ToDecimal(price);
msp.Shop_Deposit = Convert.ToDecimal( pprice);
msp.Shop_Name = shopname;
msp.Shop_Phone = shopphone;
msp.Shop_QQ = qq;
msp.Shop_MemID = Mem_Id;
if (bsp.AddShop(msp) > 0)
{
return "1";
}
else {
return "0";
}
}
}
断点进不到后台,但是前台的success可以输出alert("失败"),按理说,进不到后台,那success函数回调是不成功的,为什么success还能显示alert的函数?(但是不是显示alert(“成功!”));
5 个解决方案
#1
你可以alert(data.d)看看返回值是什么,另外,如果你要判断是否进入了后台,你可以什么操作都不做,直接 return "1"; 看看alert(data.d) 是什么,VS的调试,有的时候,也挺奇怪的
#2
//datatype:"json",
///==>注意区分大小写
dataType:"json",
而且返回json要指定contentType,发送的数据也需要为JSON格式的字符串,不能为json对象,会被转为键值对,导致出错
function fabu() {
var title = $("#shop_title").val();
var describe = $("#shopdescrib").val();
var type = $("#sel_type").val();
var addres = $("#shop_addres").val();
var price = $("#shop_price").val();
var pprice = $("#shop_pprice").val();
var shopname = $("#shop_pname").val();
var shopphone = $("#shop_phone").val();
var qq = $("#shop_QQ").val();
//public static string Addshop(string title,string decribe,string type,string address,string price,string pprice,string shopname,string shopphone,string qq)
$.ajax({
type: "post",
url: "AddShop.aspx/Addshop",
dataType: "json", /////////
contentType: "application/json;", //////////////
/////////////注意data数据
data: '{ "title":"' + title + '", "describe":"' + describe + '", "type":"' + type + '", "addres":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',
success: function (data) {
if (data.d == "1") {
alert("成功");
}
else {
alert("失败"); //在后台断点的时候,不能进入到后台的断点部分,但是请求完数据后,执行的是这个语句
}
}
});
}
#3
按照你的改了,success进不去了,直接进入了error函数,路径应该没问题
#4
你url 对不,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
打印错误信息看看
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
打印错误信息看看
#5
晕。。参数名称不一致。没注意看你代码
public static string Addshop(string title,string decribe,string type,string address,string price,string pprice,string shopname,string shopphone,string qq)
data: '{ "title":"' + title + '", " describe":"' + describe + '", "type":"' + type + '", " addres":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',
传递的json键名称也要和方法一致,要不会报错
data: '{ "title":"' + title + '", " decribe":"' + describe + '", "type":"' + type + '", " address":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',
public static string Addshop(string title,string decribe,string type,string address,string price,string pprice,string shopname,string shopphone,string qq)
data: '{ "title":"' + title + '", " describe":"' + describe + '", "type":"' + type + '", " addres":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',
传递的json键名称也要和方法一致,要不会报错
data: '{ "title":"' + title + '", " decribe":"' + describe + '", "type":"' + type + '", " address":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',
#1
你可以alert(data.d)看看返回值是什么,另外,如果你要判断是否进入了后台,你可以什么操作都不做,直接 return "1"; 看看alert(data.d) 是什么,VS的调试,有的时候,也挺奇怪的
#2
//datatype:"json",
///==>注意区分大小写
dataType:"json",
而且返回json要指定contentType,发送的数据也需要为JSON格式的字符串,不能为json对象,会被转为键值对,导致出错
function fabu() {
var title = $("#shop_title").val();
var describe = $("#shopdescrib").val();
var type = $("#sel_type").val();
var addres = $("#shop_addres").val();
var price = $("#shop_price").val();
var pprice = $("#shop_pprice").val();
var shopname = $("#shop_pname").val();
var shopphone = $("#shop_phone").val();
var qq = $("#shop_QQ").val();
//public static string Addshop(string title,string decribe,string type,string address,string price,string pprice,string shopname,string shopphone,string qq)
$.ajax({
type: "post",
url: "AddShop.aspx/Addshop",
dataType: "json", /////////
contentType: "application/json;", //////////////
/////////////注意data数据
data: '{ "title":"' + title + '", "describe":"' + describe + '", "type":"' + type + '", "addres":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',
success: function (data) {
if (data.d == "1") {
alert("成功");
}
else {
alert("失败"); //在后台断点的时候,不能进入到后台的断点部分,但是请求完数据后,执行的是这个语句
}
}
});
}
#3
按照你的改了,success进不去了,直接进入了error函数,路径应该没问题
#4
你url 对不,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
打印错误信息看看
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
打印错误信息看看
#5
晕。。参数名称不一致。没注意看你代码
public static string Addshop(string title,string decribe,string type,string address,string price,string pprice,string shopname,string shopphone,string qq)
data: '{ "title":"' + title + '", " describe":"' + describe + '", "type":"' + type + '", " addres":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',
传递的json键名称也要和方法一致,要不会报错
data: '{ "title":"' + title + '", " decribe":"' + describe + '", "type":"' + type + '", " address":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',
public static string Addshop(string title,string decribe,string type,string address,string price,string pprice,string shopname,string shopphone,string qq)
data: '{ "title":"' + title + '", " describe":"' + describe + '", "type":"' + type + '", " addres":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',
传递的json键名称也要和方法一致,要不会报错
data: '{ "title":"' + title + '", " decribe":"' + describe + '", "type":"' + type + '", " address":"' + addres + '", "price":"' + price + '", "pprice":"' + pprice + '", "shopname":"' + shopname + '", "shopphone":"' + shopphone + '", "qq":"' + qq + '"}',