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 ReddyPosted Jun 24, 2014, 1:58 AM
success: function (data) {
if(data!=null)
{
alert("data");
}
else
{
alert("error")
}
},
Anupam SinghPosted Jun 24, 2014, 12:49 AM
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.
Nimit JoshiPosted Jun 23, 2014, 10:24 PM
jeevan kumarPosted Jun 23, 2014, 3:07 PM
$('#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..."); }
});
});
});
Srikanth ReddyPosted Jun 11, 2014, 8:50 AM
Nimit JoshiPosted Jun 11, 2014, 6:36 AM
Srikanth ReddyPosted Jun 11, 2014, 5:33 AM