javascript - Jquery var to php but do not return -
i have html form want send php javascript variables. these js vars not in form. how can both th php class?
below code have far.
$("#login_form").submit(function() { event.preventdefault(); $.post('../class/login.class.php',{ //.. serialized form data screen:screen.width //...ser //... },function(data){ alert(data); window.location.href = ""; }); });
the screen
variable ends in login.class.php
when gets end of php file... returns above javascript function.
even when using header
php returns javascript function. reads page , returns thats returned in there. echo $_post['hash']; header('location: ../index.php'); die();
only if use window.location.href = "";
in javascript can redirect correct page after processing javascript data in login.class.php
file (redirecting correct page isn't reason i'm asking question...fyi)
how can send variables jquery / javascript php , continue there? aka not return (success) function variables send from.
if understand correctly want pass serialized form data plus jquery variables if that's case use serializearray()
var data = $('#myform').serializearray(); data.push({var1: 'value', var2: 'value'}); $.post("mypage.php", data);
edit
i think got trying do, if submit form using jquery ajax return success function because redirection in php redirect ajax request , not current "screen".in case try following (not 100% here goes): add hidden fields form say:
<form action="/class/login.class.php"> <!-- form content n stuff --> <input id="var1" name="var1" type="hidden" value="somevalue" /> <button id="letsgo" type="submit">submit</button> </form> $('#letsgo').click(function(e) { e.preventdefault(); var form = $(this).closest('form'); $('#var1').val('dasvalue'); // replace many hidden inputs need form.submit(); });
hope helps.
Comments
Post a Comment