unplugged_web Posted July 6, 2015 Share Posted July 6, 2015 I've got a link that is sent using AJAX but no results are being sent. The link is: <a href="javascript:void(0);" data-flavour="Berry" class="nav_link Berry">Berry</a> While the AJAX is: <script type="text/javascript"> $('.nav_link').on('click', function(){ event.preventDefault(); var flavour = $(this).data('flavour');$.get('/filter/?search=' + $(flavour).val(),{flavour:flavour}).done(function(data){ if(!$('#container').hasClass('is-loaded')) { $('#container').addClass('is-loaded'); $('#container').html(data);} else { $('#container').append(data);} }); } );</script> When I get the filter page is says the search value is undefined. If I go directly to the page with what should be sent via AJAX (filter/?search=Berry) then I get all of the relevant results I don't get any errors at all either Link to comment Share on other sites More sharing options...
justsomeguy Posted July 6, 2015 Share Posted July 6, 2015 var flavour = $(this).data('flavour');What is that going to return, what is flavour going to be set to? Because I doubt you're using it correctly here:$(flavour).val() Link to comment Share on other sites More sharing options...
Ingolme Posted July 7, 2015 Share Posted July 7, 2015 Note that this line does nothing: event.preventDefault(); because event is not defined (except in old versions of Internet Explorer where there was a global variable called "event", but it didn't have a preventDefault() method. You should set event in the function: $('.nav_link').on('click', function(event){ Link to comment Share on other sites More sharing options...
justsomeguy Posted July 7, 2015 Share Posted July 7, 2015 Note that this line does nothing:That would actually be a fatal error, something like undefined doesn't have a method called preventDefault, or trying to call a method on an undefined object. That one is definitely fatal. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now