googlexx Posted July 22, 2013 Share Posted July 22, 2013 i'm trying to call a php file using ajax and it seems to be returning false, but i have no idea why. any ideas? <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <form method="get" action="test.php"> <input id="myvar" type="hidden" name="albumid" /> <button type="submit" id="btnsubmit">Submit</button> </form> <script type="text/javascript"> $('form').submit(function() { $.ajax({ url: "newAlbum.php", data: {albumid: $('#myvar').val()}, success: function(data){ var album = data; $('#myvar').val(album); return true; } }); return false; }); </script> newAlbum.php <?php echo '11'; ?> test.php <?php echo $_GET["albumid"]; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted July 22, 2013 Share Posted July 22, 2013 What gives you the impression it is returning false? Quote Link to comment Share on other sites More sharing options...
robertjoep Posted July 23, 2013 Share Posted July 23, 2013 (edited) I think you need to indicate the type of data you are sending to the other page. e.g. post, get, json, etc.. This is the format that i use: $.ajax({ type: 'post' , url: 'path/to/file.php' , data: { send: 'var' } , success: function( data ) { $('#target_element').html(data); } }); Edited July 23, 2013 by robertjoep 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.