当我尝试将数据发送到服务器时,没有得到预期的结果

时间:2018-11-04 14:03:55

标签: php jquery json ajax getjson

我有一个使用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}中。我想做的就是根据关键得到一组案例。

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

$( "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();

0 个答案:

没有答案