I am using jQuery Validate to make sure an entered report number is valid in a SQL database. I am doing this with an asmx web service that is returning a true/false boolean when passed the report number. The web service is working fine and is returning a JSON encoded response like one of the following:
<?xml version="1.0" encoding="UTF-8"?>
<boolean xmlns="http://tempuri.org/">true</boolean>
or
<?xml version="1.0" encoding="UTF-8"?>
<boolean xmlns="http://tempuri.org/">false</boolean>
However, when I try to call it in the following jQuery it keeps returning [object Object] instead of the true/false boolean like I am expecting.
$(function() {
$("#form1").validate({
rules: {
tbAuto: {
remote: function () {
var r = {
url: "ReportList.asmx/ValidateInReports",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{'ReportNumberSearch': '" + $('#tbAuto').val() + "' }",
dataFilter: function (data) { return (JSON.parse(data)).d; }
}
$("#txtID").val(r);
// return r;
}
}
},
messages: {
tbAuto: { remote: "check" }
}
});
});
I have commented out the return line and returned it to the textbox just to see what it was returning. When the return r; was in their it was acting as though it was returning true all the time.
This is not currently in my life application, just trying to get it to work in a test environment. This is my test code that goes with the jQuery above:
<form id="form1" runat="server">
<div class="demo">
<div class="ui-widget">
<label for="tbAuto">Report Number: </label>
<asp:TextBox ID="tbAuto" class="tb" runat="server">
</asp:TextBox><br />
<label for="txtID">ID: </label>
<asp:TextBox ID="txtID" CssClass="tbb" runat="server" />
</div>
</div>
</form>
Thanks in advance for any thoughts or suggestions.
I ended up going a completely different route using the blur instead of validation. I had trouble with this as well, but eventually was able to figure it out. The post with the resolution can be found here.