This is driving me nuts. This is as simple an example as it can get. All the links are absolute so you should literally be able to copy this into a file called "test.html", load it up, hit submit, and see the word "empty" be changed to the results of http://www.w3schools.com/php/welcome.php.
<!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('#create').submit(function() { $.ajax({ data: $(this).serialize(), type: $(this).attr('method'), url: $(this).attr('action'), success: function(response) { $('#created').html(response); } }); return false; }); }); </script> </head> <body> <form id="create" method="POST" action="http://www.w3schools.com/php/welcome.php"> <input type="submit" value="Submit" /> </form> <div id="created">empty</div> </body> </html> When I click Submit, nothing happens. What am I doing wrong?
console.logto see which parts of the code are being hit? Have you tried a debugger? How about inspecting network activity (potentially through Chrome dev tools or Fiddler)?XMLHttpRequest cannot load http://www.w3schools.com/php/welcome.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.