Jump to content
Sign in to follow this  
w3schoon

How to fix Ajax Error 404?

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...