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

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -