JQuery .Post() And PHP

Discussion in 'jQuery' started by MrQuidam, Feb 1, 2010.

  1. #1
    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);
    			}
    		});
    	}
    }
    Code (markup):
    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';
    }
    PHP:
    I've viewed $("#statusForm").serialize()'s output, and it is passing statusUpdate (statusUpdate=the_value_here), but the PHP doesn't seem to be able to access it via $_POST.

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

    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!
     
    MrQuidam, Feb 1, 2010 IP
  2. MrQuidam

    MrQuidam Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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!
     
    MrQuidam, Feb 1, 2010 IP