【问题标题】:Safari Json.stringify errorSafari Json.stringify 错误
【发布时间】:2015-09-30 16:36:36
【问题描述】:

我收到此错误(只有 Safari,Chrome 和 Firefox 可以正常工作):SyntaxError: Unexpected token '}'。函数上的属性名称“params”后面应该有一个“:”:

  function buildprojecttypeselect(params){
  var result;
  $.ajax({
    type: "POST",
    url: "include/builds/buildprojecttypeselect.php",
    async: false,
    contentType: "application/json",
    data: JSON.stringify({params}),
    success: function(data) {
       result = $.parseJSON(data);
    }
  });

return result;

}

json.stringify({params}) 有问题。

params 是一个数组 =

[Object { 0="2",  1="name1",  id_projecttype="2"}, 
Object { 0="3",  1="name2",  id_projecttype="3"}, 
Object { 0="4",  1="nam3",  id_projecttype="4"}]

【问题讨论】:

    标签: arrays json ajax safari


    【解决方案1】:

    params 周围不需要大括号:

      function buildprojecttypeselect(params){
      var result;
      $.ajax({
        type: "POST",
        url: "include/builds/buildprojecttypeselect.php",
        async: false,
        contentType: "application/json",
        data: JSON.stringify(params),
        success: function(data) {
           result = $.parseJSON(data);
        }
      });
    
    return result;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-07
      • 2011-12-27
      • 2018-07-21
      • 1970-01-01
      • 2019-12-09
      • 2012-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多