i built contact form in aspx 3.5 and i'm using jquery to send it to web service (asmx).
the web service need to return success or error code. the problem is that at the web method i get only single value and not array. I'm kind of new in ajax and i tried a lot of solutions but without any results.. please if you can only explain me the principle of what to do it also be good..
this is the client side:
$(document).ready(function()
{
$("#submit").click(function(event)
{
$.ajax
({
type: "POST",
url: "RVContactFormMailer.asmx/HelloToYou",
data: "{'name': '" + $('#name').val() + "', 'company':'" + $('#company').val() + "', 'phone':'" + $('#phone').val() + "', 'email':'" + $('#email').val() + "', 'questions':'" + $('#questions').val() + "'}" ,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
AjaxSucceeded(msg);
}, error: AjaxFailed
});
});
in firebug its sends correctly:
{'name': 'jhon', 'company':'example', 'phone':'123', 'email':'[email protected]', 'questions':'hello'}
the asmx code is (please ignore the names, its example..:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService] // To allow this Web Service to be called from script, using ASP.NET AJAX or JQuery.
[ToolboxItem(false)]
public class RVContactFormMailer : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloToYou(string name)
{
return "Hello " + name;
}
}
when i debug i see that the input parameter "name" contains only one string - i dont know how to get the full json string that i send to the service and contains all the form data - i want to desirialize it to string array or something like, and process it. how can i do that? Thanks, Eranio.