Skip to content Skip to sidebar Skip to footer

How To Pass A Value To Php Variable By Ajax

this is my javascript code : function category(row){ dataparam = 'oper=delete&row='+row; $.ajax({ type: 'POST', url: 'multiupload.php', data: d

Solution 1:

In your dataparam variable you have "oper=delete&row="+row; and in the PHP code you test for $_REQUEST['opers']), since oper <> opers, the failure is perfectly normal, just add or remove the s somewhere.

Solution 2:

It looks like you have this wrong, $_REQUEST['opers'] it should be $_REQUEST['oper']

$opers = (isset($_REQUEST['oper']) and$_REQUEST['oper'] != '' ) ? $_REQUEST['oper'] : '';  

if($opers == "delete") {
    $row=$_REQUEST['row'];
    echo$row;
}

I would also recommend that as you are expecting the values to come via URL you use the appropriate super global which is $_GET. There is a very small chance that a $_COOKIE could screw you over. If you use them and hapen to give it the value of 'oper'.

Solution 3:

You want $_REQUEST['opers'] while you pass oper. Notice the additional "s".

Solution 4:

$opers = (isset($_REQUEST['oper']) and$_REQUEST['oper'] != '' ) ? $_REQUEST['oper'] : '';  
if($opers == "delete")
{
     $row=$_REQUEST['row'];
     echo$row;
}

Hopefully the problem is with the extra curly brackets. Check it. I have corrected the code. Let me know if it works. And there is an extra s in opers.

Post a Comment for "How To Pass A Value To Php Variable By Ajax"