【问题标题】:phonegap ajax not working with valuephonegap ajax 无法使用价值
【发布时间】:2017-05-30 21:52:12
【问题描述】:
    <script>
    $(document).ready(function() {
    $.ajax({url: "http://somedomain/app/district.php", success: function(result){
    $("#district").html(result);
    }});

    $.ajax({url: "http://somedomain/app/category.php", success: function(result){
    $("#crop-category").html(result);
    }});

        $('#district').change(function(){
    var value=$('#district').val();
    $('#upazila').parent().find('span').html("<span>&nbsp;</span>");
    $.ajax({
      url: "http://somedomain/app/upazila.php",
      type: "get", //send it through get method
      data:{value},
      success: function(response) {
        $("#upazila").html(response);
      },
      error: function(xhr) {
        //Do Something to handle error
      }
    });

});

    });

</script>

这是我的 jquery 代码,我正在构建 android 应用程序。 对于前 2 个 ajax 请求,我得到了值,但是当我通过 get 请求传递一些变量时,代码不起作用。在调试心情它说 Uncaught SyntaxError: Unexpected token } index.html:36 这是

数据:{值},

但它在浏览器上运行良好...... 请帮忙。

【问题讨论】:

    标签: javascript android jquery cordova jquery-mobile


    【解决方案1】:

    问题是在您的第三次ajax 调用中,data 字段不是有效对象,data 应该是对象、字符串或数组。通过value如下图:

    data: value
    

    您无需在花括号内提及它。或者如果它是一个字符串或数组,并且您希望它作为一个对象传递,则如下所示传递它:

    data: {value: value}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多