在PHP中读取JSON数组

I have a this variable:

var order = $('#listadoImages').sortable('serialize');

When send the order var from JSON to PHP, shows "id[]=18&id[]=19", my problem is I can not read that in php. I tried with foreach but returns error.

My ajax code:

 $("#mainAction").click(function(){
         //alert("New position: " + ui.item.index());
            var order = $('#listadoImages').sortable('serialize');
            var rutas = [];
            $('#listadoImages li').each(function(index, li){
                var bg = $(this).find('span').css('background-image');
                bg = bg.replace('url(','').replace(')','').replace(/\"/gi, "");
                var res = bg.substring(42);

                if(index == 0){
                    rutas += res;
                }else{
                    rutas += ";" + res;
                }

            });


            //alert(rutas);
            $.ajax({
              type: "POST",     
              url: "functions/guardar.php",
              data: {
              orden : order,
              path : rutas
              },
              "success":function(data){

              }
            });
        });

My PHP code:

$paths =  $_POST['path'];
$orden = $_POST['orden'];
$rutas = explode(";", $paths);

if(isset($paths)){

    $sql = "SELECT * FROM imagenes";
    $respuesta = mysql_query($sql);

    if($respuesta){
    $i=0;
        while( $rs = mysql_fetch_assoc($respuesta) ){
            $rutaBD = $rs['ruta_imagen'];
          foreach ($orden as $k => $value) {
            foreach ($rutas as $key => $rut) {
                        for($i=0;$i<count($rut);$i++){
                            if($rutaBD == $rut){
                               //Here Update Statment
                            }
                        }
                }       
            }


         }      

    }

Thank you for readme. I hope someone can help me. Thank you! Regards.

查看全部
weixin_33698823
weixin_33698823
2016/10/03 18:14
  • foreach
  • json
  • php
  • ajax
  • 点赞
  • 收藏
  • 回答
    私信

1个回复