douzhi9939 2015-10-20 16:51
浏览 52
已采纳

如何将数组值从javascript ajax传递给php并读取它?

I am new to php and, I am trying to save more then one values the value will increase dynamically. I am send the array value by the following method from javascript code.

    $(".dyimei").each(function(i,value){
        if($(this).val()=="")
            err_flag=1;     
        json_IMEI.push($(this).val());
    });

    //json_IMEI=["343","3453"]  <= eg im getting this value


    var strarray=JSON.stringify(json_IMEI);
   //strarray = "["343","3453"]"; <= here this value

 ajaxRequest.open("POST","save_settings.php?strarray="+strarray, true);
 ajaxRequest.send(null);

And I am accessing this value from serverside code (save_settings.php)

$strarray=(isset($_REQUEST['strarray']) ? $_REQUEST['strarray'] : '');
$strarray=json_encode($strarray);

$arrlength = count($strarray);
    for($x = 0; $x <= $arrlength; $x++)
    {
        $IMEI=$strarray[$x];
        $insert_imei="insert into imeidetails(ProductID,IMEIID) values('$tabid','$IMEI');";
        $run_query=mysqli_query($dbcon,$insert_imei);
    }

But I am getting the $IMEI values is always 0 (zero)

  • 写回答

1条回答 默认 最新

  • dsakktdog498483070 2015-10-20 16:56
    关注

    change this:

    $strarray=json_encode($strarray);
    

    to:

    $strarray=json_decode($strarray);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?