I am using a third party tool on my ASP.NET website.
The third party tool opens a pop up box on the screen and collects first name, last name, age etc, and then pass them to the same function which opened the box.
This function is in a .js file. So, I can get first name, last name, age etc in the .JS file of the third party tool.
I want insert those details from the .JS file to SQL database. I hope the best way is to call a Web Service (C#), pass the information to the C# file and it will insert into database. I have to do the same for collecting data from database as well.
When I try to call the WebService from .JS file, I am getting an error - 'MyWebService1' is undefined.
Could you please help me to fix it?
Is there any better approach?
Thanks
Jaganathan BantheswaranPosted Oct 24, 2013, 2:08 AM
I consider, you are using jQuery.
Try something similar to the below one.
Comment the [System.Web.Script.Services.ScriptService] attribute from your service class.
Use the below script in your html page
var person = {};
person.ID = $('#txtID').val();
person.Name = "Jagan";
var pdata = { "p": person };
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/SampleService.asmx/GetPesonnelSalary",
data: JSON.stringify(pdata),
dataType: "json",
async: true,
success: function (data, textStatus) {
if (textStatus == "success") {
if (data.hasOwnProperty('d')) {
msg = data.d;
} else {
msg = data;
}
alert(msg);
}
},
error: function (data, status, error) {
alert("error");
}
});