jQuery validate plugin is pretty awsome. However it doesn’t do everything. That’s why the plugin have the addMethod function. And I need to add an ajax duplicate check for an email input. Here’s the method i wrote. There might be a better way. I would love to know.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
jQuery.validator.addMethod("checkForDupeEmail", function(value, element, param){
var ajaxFunc = $.ajax({
async:false, //we have to set it to false, it does not return a value before we even complete the request.
data:'email='+($.trim(value)),
type:'POST',
url:'/employees/ajax_checkDupe',
dataType:'text',
});
//here we check the response
if(ajaxFunc.responseText == 1)
return true;
else
return false;
});

3 Comments
И придратся не к чему, а я так люблю покритиковать…
wow! this is cool! I’m working almost 3 day finding the right way to post data to the other page, this code help me a lot and solve my problem. I learn from this code, that if you want to use the return value of ajax you have to use the handler like responseText or responseXML. Thank you very much!
(sorry if you don’t understand my English).
wow! this is cool! I’m working almost 3 day finding the right way to post data to the other page, this code help me a lot and solve my problem. I learn from this code, that if you want to use the return value of ajax you have to use the handler like responseText or responseXML. Thank you very much!
(sorry if you don’t understand my English).