0

js ページで ajax リクエストを使用して json オブジェクトを渡したいのですが、それを行うと、php で $_POST 配列が空になります。

JavaScript ページ

    function invia(cat,subcat)
{
    var tipo = cat.options[cat.selectedIndex].text;
    var sottotipo = subcat.options[subcat.selectedIndex].text;

    var lat = getLatitudine();
    var lon = getLongitudine();     

        $.ajax({    
            type:'POST',                                
            url: "apriSegnalazione.php",
            dataType: "json",
            data : { 
                type: {type: tipo, subtype: sottotipo};
                lat: lat,
                lng: lon
                }           
            }).success(function(data){

                alert( "Data Saved: "+ data);

            });

}

これは私のphpページです

<?php  
header('Content-Type: application/json',true);
header('Accept: application/json');

  $tipo = $_POST['type'];    
  $ris = json_decode($tipo,true);
    var_dump($ris);

?>

助言がありますか?

4

1 に答える 1

0

この行から;,

type: {type: tipo, subtype: sottotipo};

あるべき、

type: {type: tipo, subtype: sottotipo},

スクリプトにエラーがありSyntaxError: missing } after property list、ajax リクエストを処理している場合は、常に mozilla の firebug アドオンなどのツールを使用してください。上記のエラーは、firebug のコンソール パネルで確認できます。

于 2013-06-12T15:40:16.047 に答える