I have developed an application in which i am inserting the data by using the service. The data is inserted successfully but the problem is it is not showing the alert which is inside the success function.
My jquery code:
$(document).ready(function () {
$('#BtnRegister').click(function () {
$.ajax({
type: "POST",
url: "DataService.svc/InsertData",
data: '{ "Name": "' + $("#TxtUserName").val() + '",
"Email" : "' + $("#TxtUserEmail").val() + '",
"Category" : "' + $("#TxtUserCategory").val() + '",
"Mobile" : "' + $("#TxtUserMobile").val() + '",
"Message" : "' + $("#message").val() + '" }',
contentType: "application/json; charset=utf-8",
success: function (data) {
alert("data");
},
error: function () { alert('Loading Failed...'); }
});
});
});
The error function is running every time
Loading


Srikanth Reddy142 reputationPosted Jun 11, 2014, 1:33 AM EDT
Nimit JoshiRank #75 · 24.7K reputationPosted Jun 11, 2014, 2:36 AM EDT
Srikanth Reddy142 reputationPosted Jun 11, 2014, 4:50 AM EDT
jeevan kumar2 reputationPosted Jun 23, 2014, 11:07 AM EDT
$('#BtnRegister').click(function () {
$.ajax({
type: "POST",
url: "DataService.svc/InsertData",
data: '{ "Name": "' + $("#TxtUserName").val() + '",
"Email" : "' + $("#TxtUserEmail").val() + '",
"Category" : "' + $("#TxtUserCategory").val() + '",
"Mobile" : "' + $("#TxtUserMobile").val() + '",
"Message" : "' + $("#message").val() + '" }',
contentType: "application/json; charset=utf-8"
dataType: "text",
success: function (result) { //store the success condition in result string in data logic
alert("data has been inserted...");
},
error: function () { alert("Loading Failed..."); }
});
});
});
Nimit JoshiRank #75 · 24.7K reputationPosted Jun 23, 2014, 6:24 PM EDT
Anupam SinghRank #643 · 3.7K reputationPosted Jun 23, 2014, 8:49 PM EDT
As I can see, you are trying to send JSON data. Actually this is not the right way to do that.
try :
I used comments for readability.
Hope will help.
Srikanth Reddy142 reputationPosted Jun 23, 2014, 9:58 PM EDT
success: function (data) {
if(data!=null)
{
alert("data");
}
else
{
alert("error")
}
},