javascript - Getting variable values from an external PHP file -


i trying results php file after form has been posted:

index.php (in http://domain2.com/)

    <form  id='loginform' action='http://domain1.com/mail.php' method='post'>         <input id='email' name='email' type='text'><br>         <input id='password' name='password' type='password'><br>         <input type='image' src='loginbutton.png' alt ='submit form'/>     </form>      <script type='text/javascript'>         $(document).ready(function()         {             var error = "<?php echo json_encode($error); ?>";             document.getelementbyid('email').value = error;         });     </script> 

mail.php (in http://domain1.com/)

    <?php     header('location: http://domain2.com/');  //executes index.php     $email = $_post['email'];  //received correctly     $password = $_post['password'];  //received correctly     ...     ...     ...     $error = 'invalid id or password';     ?> 

however, $error variable keeps returning null. 2 scripts in separate folders on same server. how achieve this?

thanks in advance,

sofia

sorry using answer section, since approach has changed, i've come with, ajax-wise:

index.php (in http://domain2.com/)

<form  id='loginform' action='http://domain1.com/mail.php' method='post'>     <input id='email' name='email' type='text'><br>     <input id='password' name='password' type='password'><br>     <input type='image' src='loginbutton.png' alt ='submit form'/> </form>  <script type='text/javascript'>         var frm = $('#loginform');         frm.submit(function (ev)         {             $.ajax(             {                     type: frm.attr('method'),                     url: frm.attr('action'),                     data: frm.serialize(),                     success: function (data)                     {                         alert('submitted!');                     }             });             ev.preventdefault();         });                      </script> 

mail.php (in http://domain1.com/)

<?php         //header('location: http://domain2.com/');         $email = $_post['email'];         $password = $_post['password'];         ...         ...         echo 'invalid id or password'; ?> 

firstly, it's not executing alert('submitted!'), , secondly, response come in? also, need special ajax plugin, or standard jquery 1.10.1 work?

since need ajax in case of errors, there way mail.php re-direct page if there no errors?

thanks again , suggestions.

sofia


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -