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
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();
	  }
	});

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.