I finally figured out how to do this: I set this.data to my json
string inside the function assigned to the $.ajax beforeSend property.
I then added a function for the $.ajax dataFilter property to convert
the json response to an object (using jQuery JSON at
http://code.google.com/p/jquery-json/) so I could return appropriate
server message and status (my Web methods response object is custom
ServiceResult class consisting of bool Success, string Message and
Object Data):

var validatorOptionsPhone = {
        required: true,
        minlength: 8,
        number: true,
        remote: {
                url: 'CorpSiteService.asmx/ValidatePhoneNumber',
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                beforeSend: function(XMLHttpRequest) {
                        // Explicitly setting the $.ajax data property is 
required when
using POST and remote validation.
                        this.data = $.format("{'phoneNumber':'{0}', 
'countryId':'{1}',
'selectedCarrierId':'{2}'}",
                                $uxPhoneNumber.val(), $uxCountries.val(), 
$uxCarriers.val());
                        setValidationMessage($uxPhoneNumber, 'Verifying mobile 
number...');
                },
                dataFilter: function(json) {
                        var msg = $.evalJSON(json);
                        if (!isNullOrEmpty(msg.d.Message)) {
                                // Assign a custom message returned
from the service
                                validator.settings.messages.phoneNumber.remote 
= msg.d.Message;
                        }
                        return msg.d.Success;
                }
        }
};

Hooray! I can now remove HttpGet from my web.config and have a more
secure jQuery ASMX solution.

On Apr 9, 11:23 pm, pbarnes <pmbar...@gmail.com> wrote:
> I am using the jQuery Validator plugin withASMXWeb services. I would
> like not to have to use HTTP GET (for security reasons). I can
> successfully use POST when directly using $.ajax, but when it comes to
> the Validator plugin, I'm having a difficult time setting the
> remote.data property in the rules for a specific field that is
> remotely validated.
>
> Out of the box the remote validation in the jQuery Validator plugin
> uses GET, which permits setting the $.ajax.data property to an object.
> This means I can assign each data object property to an anonymous
> function that returns the latest values entered or selected by the
> user. For example, for myphoneNumberfield I can set:
>
>                                         data: {
>                                                 countryId: function() { 
> return $uxCountries.val(); },
>                                                 selectedCarrierId: function() 
> { return $uxCarriers.val(); }
>                                         },
>
> But for POST to work, among other changes the $.ajax.data property
> must be a string formatted as json. I cannot figure out a way to
> update this string after the Validator object initializes
> ($form.validate()) on page load. If I try to use an anonymous function
> to return a string, $.ajax seems to just do a .toString() operation on
> the function, returning JavaScript object type info.
>
> Can anyone suggest a good way to set the remote.data property for POST
> operations? It would be really nice if I could do something like data:
> $.format("{'phoneNumber':'{0}', 'countryId':'{1}',
> 'selectedCarrierId':'{2}'}", $phoneNumber.val(), $countries.val(),
> $selectedCarrierId.val()), and the validator would always use the
> latest values, not the values at the time when the validator is
> initialized.

Reply via email to