Jump to content

Ajax not working


sonicthehedgehog
 Share

Recommended Posts

I'm trying to get a form the submit and get the results from a database without the page reloading.

I've got a form and want the results to update whenever somebody clicks on a checkbox or button. The form works and gets the right results but only if the page loads.
This is the code I'm using:
$('.filter_link').on('click', function(e) {  e.preventDefault // prevent form submission  $.ajax({    url:'/results/index.php',    data: $(this).serialize(), // serialize form data and attach to request    type:'POST',    success:function(results) {      $(".result").html(results);    }  });});
I don't get any errors at all and nothing happens. The form also has the /results/index.php as the action too and filter_link is the class id for the checkboxes and buttons. I've also got a div in the page with the class 'result'
Edited by sonicthehedgehog
Link to comment
Share on other sites

I don't understand

 

I've now managed to get it to load the new page within the div but it's not loading the results

 

It should only load html content and results that would normally be between and NOT including <body>...</body> tags. and IT SHOULD work just fine referencing class on checkbox only.

 

So e.preventDefault(); prevents checkbox being checked, AND not just preventing submission of input type submit or button in this case right?

 

Just place simple echo $_POST['name_used_for_check_box']; in index.php to make sure it is picking up this value, then go on from there to make sure sql query, connection is correct, since we have no idea what you are actually doing in index.php file.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...