I'm trying to use the remote validation option to call an .asmx web service. I understand for this to work I need to return a json true/false from my webservice. In order for my .asmx webservice to return json instead of xml I need to do the following (1) set type to POST (2) set dataType to json (3) set content type to json
....
remote: {
type:
"POST"
,
dataType:
"json"
,
contentType:
"application/json; charset=utf-8"
,
url:
"../WS/Administration.asmx/OrganisationExists"
data: "{'company':'" + $("#Company").val() + "'}" <--- Problem is here
}
....
<
p
>
<
label
for
="Company">
Company Name:
</
label
>
<
input
id
="Company"
type
="text"
name
="Company"
maxlength
="50"
/></
p
>
....
This works in so far as my webserivce now returns the correct json but the problem
is the data passed to the webserivce contains a blank value i.e. '{company:''}'. It
seems like the $("#Company").val() returned blank.
I've tried to pass the data as follows:
data: {
company:
function
() {
return
$(
"#Company"
).val();
}}
and this does return the value of the #Company input field, but the data is now a querystring not json i.e. company=test.
Can anyone let me know why this (data: "{'company':'" + $("#Company").val() + "'}" )
isn't returning a value from my input field
or maybe suggest another way that I can
create a json oject to pass to my web service.
Thanks for your help!!
Ciaran