Hi guys
I have problem how to send data from Jquery to asp service
always give me an error
Failed to load resource: the server responded with a status of 500 (Internal Server Error) in Console
this is the code
var Info = $("#basketInfo").val();
var text = "some thing";
$.ajax({
url: 'Services/WebServiceAjax.asmx/InsertMethod',
type: 'POST',
dataType:"json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
"Items": text,
"BasketInfo": Info
}),
success: function (response) {
alert("Record Has been Saved in Database");
},
error: function (xhr, ajaxOption, thrownError)
{ alert(thrownError); console.log('there is some error'); }
});
and Service
[WebMethod]
public static string InsertMethod(string Items, string BasketInfo)
{
try
{
string[] alldata = Items.Split(',');
string[] baskInfo = BasketInfo.Split(',');
foreach (var item in alldata)
{
string[] Allitems = item.Split('_');
string itemValue = Allitems[0];
string itemID = Allitems[1];
Database Db = new Database();
string CycleDesignID = Db.CustomeQuery("select CycleDesignID from CycleDesign order by CycleDesignID desc ")[0][0].ToString();
Db.CustomInsertData(new Processes.Baskets(baskInfo[0], baskInfo[1], Convert.ToInt32(CycleDesignID), Convert.ToInt32("1")));
string BasketID = Db.CustomeQuery("select BasketID from Baskets order by BasketID desc ")[0][0].ToString();
Db.CustomInsertData(new Processes.BasketDetails(Convert.ToInt32(BasketID),
Convert.ToInt32(itemID), Convert.ToDouble(itemValue), Convert.ToDouble("3"), Convert.ToInt32("1")));
}
}
catch (Exception ex)
{
return ex.Message;
}
return "Ok";
}