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"]; ?> Link to comment https://forums.phpfreaks.com/topic/280383-calling-php-file-using-ajax-not-working/ 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? Link to comment https://forums.phpfreaks.com/topic/280383-calling-php-file-using-ajax-not-working/#findComment-1441650 Share on other sites More sharing options...
robertjoep Posted July 23, 2013 Share Posted July 23, 2013 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); } }); Link to comment https://forums.phpfreaks.com/topic/280383-calling-php-file-using-ajax-not-working/#findComment-1441764 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.