Jump to content

Jquery ajax messing with me


manix

Recommended Posts

Erm okay this is not working properly, it sends the request, it handles the response but it's not passing the data?

 

	var aldata = 'id='+ 16 + '&comment=' + ($('#comment').val()) + '&startfrom=' + <?php echo $lastid;?>;
	$.ajax({
	  url: "usercomments.php",
	  type: "POST",
	  contentType: 'text/html; charset=windows-1251',
	  data: aldata,
	  success: function(returned){
		$('#comments').html(returned+$('#comments').html()).show();
	  }
	});

 

in my PHP file I use $_POST['id'] and it says unidentified index 'id' ?

 

I tried both the above example and

 

 aldata = "{'id':'"+ u_i +"','comment':'"+ ($('#comment').val()) +"','startfrom':'"+<?php echo $lastid;?>+"'}";

 

Same result..

Link to comment
https://forums.phpfreaks.com/topic/244809-jquery-ajax-messing-with-me/
Share on other sites

The best way to track these sorts of requests is to look at the console in Firebug. It'll show the request, the response and all headers sent plus errors received etc. You should put your data like you have in the second example, but not surround it in quotes like you have. You want it to be an object, not a string. Here is how it should look:

 

	$.ajax({
	  url: "usercomments.php",
	  type: "POST",
	  contentType: 'text/html; charset=windows-1251',
	  data: {
	      id: 16,
	      comment: $('#comment').val(),
	      startfrom: <?php echo $lastid; ?>
	  },
	  success: function(returned){
		$('#comments').html(returned+$('#comments').html()).show();
	  }
	});

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.