phonegap ajax无法使用值

时间:2017-01-16 05:24:44

标签: javascript android jquery cordova jquery-mobile

    <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请求传递一些变量时,代码不起作用。在调试情绪中它说 未捕获的SyntaxError:意外的标记} index.html:36

数据:{}值,

但它在浏览器上工作正常...... 请帮忙。

1 个答案:

答案 0 :(得分:0)

问题在于,在您的第三次ajax来电中,data字段不是有效对象,data 应该是对象,字符串或数组。通过value,如下所示:

data: value

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

data: {value: value}