0

What I have here works great. But now my question is how would I make sure that before making an ajax call I have the data available in a client side model and I would look into that. If I dont find it in there then I make the call. How should I approach it?

FIND

jQuery(function(){
    jQuery('.findInStore').live('click', function(){
        var postalCode = jQuery('#postalCode').val();
        var dataModel;

        if(postalCode != ''){
            jQuery.ajax({
                type: "POST",
                url: "server side url",
                data: {
                    postalCodeValue: postalCode
                }
            }).done(function (data) {
                dataModel = jQuery.parseJSON(data);
                console.log(dataModel);
                jQuery('.error').text('');
            });
        }else{
            jQuery('.error').text('empty');
        }
    });    
});
soum
  • 1,131
  • 3
  • 20
  • 47
  • possible duplicate of [JQuery form validation](http://stackoverflow.com/questions/965967/jquery-form-validation) – Jay Blanchard May 15 '14 at 16:20
  • 1
    "If I dont find it in there then I make the call." So if you don't find the data then you do make the call? Is this for caching? – Evan Knowles May 15 '14 at 16:24
  • 1
    The [`local/sessionStorage` apis](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage) provide a client side key/value store which you can use for your purpose. – collapsar May 15 '14 at 16:35
  • @EvanKnowles--yes...that is correct. It is for caching. If I dont find the data I make the call – soum May 15 '14 at 17:31

0 Answers0