kartul Posted December 7, 2009 Share Posted December 7, 2009 hey all! i'm using jQuery and trying to submit a form without page refresh. so far it's working but it will not display the output of the php file. heres the jQ code i have so far: $(document).ready(function() { $(".button").click(function() { $("#output").hide(); $("#loading").fadeIn(); var title = $("input#title").val(); var year = $("input#year").val(); var type = $("select#type").val(); var encoder = $("input#encoder").val(); var dataString = 'title='+ title +'&year='+ year +'&type='+ type +'&encoder='+ encoder; //alert(dataString);return false; $.ajax({ type: "POST", url: "gen.movie.php", data: dataString, success: function() { $("#loading").fadeOut(); $("#output").html(dataString.responseText); <--- ***NOTE*** $("#output").fadeIn(1000); } }); }); return false; }); php file: echo $_POST['title']; ***NOTE*** i think problem starts there cause firebug gives me right return. any ideas..?! Link to comment https://forums.phpfreaks.com/topic/184282-submit-with-ajax-not-working/ Share on other sites More sharing options...
abazoskib Posted December 7, 2009 Share Posted December 7, 2009 I've never used jQuery before but a quick search turned this example up...i think you are requesting the response incorrectly. bodyContent = $.ajax({ url: "script.php", global: false, type: "POST", data: ({id : this.getAttribute('id')}), dataType: "html", success: function(msg){ alert(msg); } } ).responseText; Link to comment https://forums.phpfreaks.com/topic/184282-submit-with-ajax-not-working/#findComment-972879 Share on other sites More sharing options...
kartul Posted December 7, 2009 Author Share Posted December 7, 2009 I've never used jQuery before but a quick search turned this example up...i think you are requesting the response incorrectly. bodyContent = $.ajax({ url: "script.php", global: false, type: "POST", data: ({id : this.getAttribute('id')}), dataType: "html", success: function(msg){ alert(msg); } } ).responseText; both, my and your code, works. i just have no idea how do display returned data in html. Link to comment https://forums.phpfreaks.com/topic/184282-submit-with-ajax-not-working/#findComment-972927 Share on other sites More sharing options...
abazoskib Posted December 7, 2009 Share Posted December 7, 2009 well in my example bodyContent is the html result, so if i wanted to put this result in a div i would do something like document.getElementById('myDiv').innerHTML = bodyContent; Link to comment https://forums.phpfreaks.com/topic/184282-submit-with-ajax-not-working/#findComment-972943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.