1 Replies - 1335 Views - Last Post: 01 February 2010 - 07:57 PM

#1 animedude123   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 03-August 07

jQuery .post() and PHP

Posted 01 February 2010 - 06:15 PM

Hey,

I currently have this as a jQuery function:
function postActivity() {	
	if($('#statusUpdate').val('').length > 0 && $('#statusUpdate').val('').length <= 160) {
		$.post("process.php?type=postActivity", $("#statusForm").serialize(),
		function(data){
			if(data == 'success') {
				$('#statusUpdate').val('');
				$('#submitUpdate').attr('disabled', 'disabled');
			} else {
				$('#statusUpdate').val(data);
			}
		});
	}
}


Then I have this as the php code in process.php:
if($_GET['type'] == 'postActivity') {
	if(strlen($_POST['statusUpdate']) > 0) {
		echo $_POST['statusUpdate'];
	} else {
		echo 'What are you doing? ' . strlen($_POST['statusUpdate']);
	}
} else {
	echo 'Invalid Process';
}


I've viewed $("#statusForm").serialize()'s output, and it is passing statusUpdate, but the PHP doesn't seem to be able to access it via $_POST.

The strlen always returns 0, and when I try just printing $_POST['statusUpdate'], it doesn't return anything.

The output I'm continuing to get is: What are you doing? 0

Can anyone help with this? I have absolutely no idea why this isn't working.

Thanks in advance for any help!

Is This A Good Question/Topic? 0
  • +

Replies To: jQuery .post() and PHP

#2 animedude123   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 03-August 07

Re: jQuery .post() and PHP

Posted 01 February 2010 - 07:57 PM

Did some more debugging and I found the problem. I needed to remove the empty parameters from the .val()'s in the if statements in the function.

Problem solved!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1