Jump to content

submit with ajax not working


kartul

Recommended Posts

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..?!  :shrug:

Link to comment
https://forums.phpfreaks.com/topic/184282-submit-with-ajax-not-working/
Share on other sites

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;

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.