Jump to content

How to fix Ajax Error 404?


w3schoon

Recommended Posts

Nice be with you everyone! Problem:Every time I click delete (database) button it always trigger 404: and respond "Could not contact server". Questions:1. What is Error 404?2. And how to fix it to run Ajax successfully? Here's my code:

					var parent=$(this).closest("tr");					$.ajax({						type:'get',						url:'javascripts/delete.php',						data:'ajax=1&delete='+$(this).attr('id'),						statusCode: {							404: function() {								$("#alert").html('Could not contact server.');							},							500: function() {								 $("#alert").html('A server-side error has occurred.');							}						},						error: function() {							$("#alert").html('A problem has occurred.');						},						success:function(){							$("#alert").html('Successful!');							parent.fadeOut(300, function(){								parent.remove();							});						}					});

Thank you!

Edited by w3schoon
Link to comment
Share on other sites

it means your page javascripts/delete.php doesn't exist at the path you told the browser to look for. (404 - Page Not Found). So you need to put it there or change code to point to right path.

Link to comment
Share on other sites

@thescientist: Wow you're right, instead of includes/delete.php I misspelled the path to javascripts/delete.php. Thank you for the correction, now my $.ajax() is running successfully but the problem is: Why the selected database was not deleted after $.ajax() ran successfully? :sorry: @justsomeguy: Oh I see, in your link. I learned that my client was able to communicate with the server, but the problem is the server could not find what was requested. Can you look at my PHP request? Here's my code:

<?php   // This is includes/delete.php 		include "mysqlCon.php";			if (isset($_GET['delete'])){						$query="DELETE FROM applicants WHERE id=".(int)$_GET['delete'];			mysql_query($query);		}				mysql_close($conServ);		?>

Thank you.

Edited by w3schoon
Link to comment
Share on other sites

im not sure what you mean by the server could not find what was requested? It would probably a lot easier to turn on error handling or use mysql_error in delete.php itself first so you can debug. then integrate into the AJAX request.http://www.w3schools.com/php/php_mysql_delete.asp

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
×
×
  • Create New...