w3schoon Posted February 27, 2013 Share Posted February 27, 2013 (edited) 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 February 27, 2013 by w3schoon Link to comment Share on other sites More sharing options...
justsomeguy Posted February 27, 2013 Share Posted February 27, 2013 404 means the requested file was not found. http://en.wikipedia.org/wiki/List_of_HTTP_status_codes Link to comment Share on other sites More sharing options...
thescientist Posted February 27, 2013 Share Posted February 27, 2013 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 More sharing options...
w3schoon Posted February 27, 2013 Author Share Posted February 27, 2013 (edited) @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? @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 February 27, 2013 by w3schoon Link to comment Share on other sites More sharing options...
thescientist Posted February 27, 2013 Share Posted February 27, 2013 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 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