php - Ajax request always fails -
i'm trying send variables of username , password php file js file, ajax request fails (prints fail), no idea why.
js file:
<script> var imported = document.createelement('script'); imported.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'; document.queryselector('head').appendchild(imported); function collect() { var user = "joe"; var pass = "123"; $.ajax({ type:'post', url: 'myphp.php', data: {'username': user, 'password': pass}, success: function(){ alert("success!"); }, error: function(){ alert("fail"); } }); } </script>
php file:
<?php $myval = $_post['username']; echo($myval); ?>
<script> var imported = document.createelement('script'); imported.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'; document.queryselector('head').appendchild(imported); function collect() { var user = "joe"; var pass = "123"; $.ajax({ type:'post', url: 'myphp.php', data: {'username': user, 'password': pass}, success: function(){ alert("success!"); }, error: function(){ alert("fail"); } }); } </script> php file: <?php $myval = $_post['username']; echo($myval); ?>
when posting ajax don't need equal (=), that's problem you're having.
Comments
Post a Comment