jquery - AJAX call opens php URL instead of return to callback execution -


i have problem ajax callback:

1) in login.html page use: $.post("login.php", formdata, function(data) { }

2) in login.php: echo $data='pass';

3) problem - on submit event: browser doesn't update login.html callback. instead, displays login.php - white screen 'pass' or 'fail' string, instead of updating login.html page

you need use :

preventdefault(); 

$(function () {     var yourform = $('#yourform');     yourform.submit(function (e) {         $.ajax({             type: yourform.attr('method'),             url: yourform.attr('action'),             data: yourform.serialize(),             success: function (data) {                 alert('ok');             }         });         e.preventdefault();     }); }); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -