首页 > 解决方案 > 当我尝试向服务器发送数据时,我没有得到预期的结果

问题描述

我有一个使用 getJson 的 Jquery 函数。我正在尝试形成类似 www.mysite.com/?state=oregon 的东西。根据Jquery(“发送到服务器的数据作为查询字符串附加到URL......”),但我得到了json数据中的所有值。我做错了什么。

这是我的代码

function changeLine(line){

    $('#table_lines').html('');


    $.getJSON("../index.php", {, line}, function(data){
        var line_data = '';
        $.each(data, function(key, value){
            line_data += '<tr id="' +value.line_id+'">';

            line_data += '<td>' + otherValueTime(value.MatchTime)+'</td>';
            line_data += '<td>' + value.home+'</td>';
            line_data += '<td>' + value.away+'</td>';
            for(i=0; i < value.Cases.length; i++){
                console.log(value.Cases[i].CaseType + ' ' + value.Cases[i].CaseAway + ' ' + value.Cases[i].CaseHome);
                if(value.Cases[i].CaseType === "Game"){
                    line_data += '<td>' + value.Cases[i].CaseAway +'</td>';
                    line_data += '<td>' + value.Cases[i].Total +'</td>';
                    line_data += '<td>' + value.Cases[i].Over +'</td>';
                }


            }


        });
        $('#table_lines').append(line_data);
    });
}

在这段代码“{, line}”的行中,我尝试从 json 数组中放入键值,例如 {id:line}。我要做的是根据key得到一组case。

我想知道你是怎么做到的。我想根据选项值更改它。我确实从服务器获取数据,但我获取了所有数据。这是我如何调用该函数

$( "select" )
  .change(function () {
    var str = "";
    $( "select option:selected" ).each(function() {
      str = $( this ).val();


      $.ajax({
              method: "POST",
              url: "../index.php",
              data: { 'id' : str }

        })
    });
    changeLinea(str);
})
.change();

标签: phpjqueryjsonajaxgetjson

解决方案


推荐阅读