razorsese Posted March 13, 2012 Share Posted March 13, 2012 So i'm sending id value trough post in json format. When i open Firebug it returns the correct value but in php it's keep returning null. $('.stars').bind('click', function() { var star = this; var data = {'q' : $(star).attr('id') }; $.ajax({ type:'post', url:"voting.php", data:data, dataType:'json' }); return false; }); <?php $q=$_POST['q']; echo json_encode($q); ?> Quote Link to comment Share on other sites More sharing options...
Vel Posted March 13, 2012 Share Posted March 13, 2012 You haven't told PHP to look for any results. $('.stars').bind('click', function() { var star = this; var data = {'q' : $(star).attr('id') }; $.ajax({ type:'post', url:"voting.php", data:data, dataType:'json', success: function(result){ alert(result); } }); return false; }); Quote Link to comment Share on other sites More sharing options...
razorsese Posted March 13, 2012 Author Share Posted March 13, 2012 $.ajax({ type:'post', url:"voting.php", data:data, dataType:'json', success: function(response) { alert(response); } }); Still appear null in 'voting.php' page but the alert is showing the right value. Quote Link to comment Share on other sites More sharing options...
requinix Posted March 13, 2012 Share Posted March 13, 2012 You might be missing out on the A in AJAX. ...Uh, the first one. You can't do anything with the result unless you put it in that success function. If you try anywhere else you're going to get a null/undefined because the AJAX hasn't happened yet. Pretend that it takes 5 minutes for anything to happen: you can't get the answer immediately so you have to put in some function that'll execute later (ie, in five minutes) when it does have the answer. Meanwhile you just wait for it to come back. Quote Link to comment Share on other sites More sharing options...
Vel Posted March 14, 2012 Share Posted March 14, 2012 $.ajax({ type:'post', url:"voting.php", data:data, dataType:'json', success: function(response) { alert(response); } }); Still appear null in 'voting.php' page but the alert is showing the right value. I don't think you're using the right function for what you want. When Ajax submits a request like that voting.php is only opened on the server, with the response sent back to your machine. You'll never be able to see what's in voting.php on your machine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.