I attempted to use a basic web service (just to test if the value will populate in the JavaScript code). I experimented with a very simple snippet, but it kept returning 'undefined'. Can you offer some guidance? I have tried several solutions without success.
Below is a simple code snippet from the asmx file:
[WebMethod]
public string HelloWorld(string param1, string param2)
{
return "Hello World" + param1 + ":" + param2;
}
Here is the corresponding JavaScript code:
$.ajax({
url: "SimpleService.asmx/HelloWorld",
type: "POST",
data: {
'param1': 'value1',
'param2': 'value2'
},
success: function(response) {
alert(response.d);
}
});
I have tried accessing the results using response.text and response.value, but I am consistently receiving an undefined value.
success: function(response) {
alert(response.text);
alert(response.value);
}
In my asmx file, I also attempted replacing [WebMethod] with:
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld(string param1, string param2)
{
return "Hello World" + param1 + ":" + param2;
}
Please advise on the correct format for obtaining the result from my web service. Thank you.