how to pass a value to php variable by ajax

前端 未结 4 2034
花落未央
花落未央 2021-01-25 05:40

this is my javascript code :

function  category(row){
    dataparam = \"oper=delete&row=\"+row;
    $.ajax({
        type: \"POST\",
        url: \"multiuplo         


        
相关标签:
4条回答
  • 2021-01-25 06:04

    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'.

    0 讨论(0)
  • 2021-01-25 06:09

    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.

    0 讨论(0)
  • 2021-01-25 06:11

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

    0 讨论(0)
  • 2021-01-25 06:15
    $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.

    0 讨论(0)
提交回复
热议问题