views:

162

answers:

1

I'm using the JQuery Validation plugin. I'm using the remote option to make a call to my webservice to check if a company name exists. The webservice only accepts JSON data.

I pass the data to the webservice from the Company Input Field in my Form as follows:

data: "{'company': '" + $('#Company').val() + "'}"

But this always returns a blank value for company so the response is {'company':''} i.e. correct JSON but missing the Company Input Field value.

Can anyone shed some light on why I always get a blank value here?

Thanks for the help, Ciaran

A: 

Try this:

data: {
    company: $('#Company').val(),
    param: 1  //Second paramenter
              //you can keep adding parameters folloiwng the format 
}
Pablo
Hi Pablo,Thanks for the reply. This works to give me back the value but the format is wrong as it is a querystring instead of JSON i.e. Company=test instead of {Company:test}I wonder if this is a bug with the Validation plugin?
Click Ahead
Wierd,and where exactly do you see this Company=test? after you parse the json string in PHP? if using json_decode() it should return an associative array like [comapany] => "test", [param] => 1
Pablo
Hi Pablo, I use Firebug to debug this. If I set the data parameter as you suggested it is urlencoded with the value. If I set it as I originally suggested it is json encoded but with no value set. I agree this is strange behaviour on the part of the Validation Plugin. I'm vering down the path of using ASP.NET MVC so I don't think this will be a problem here as I can return json data using an action method that returns JSONResult in my Controller.
Click Ahead