已经过了很长时间的网址

时间:2017-04-12 08:44:42

标签: javascript php jquery json ajax

我写这个代码是为了在文件txt中保存一个url,我也会在调用按钮共享之后使用它。 当我使用这段代码时,我的问题就来了

$.ajax({
  url: "/condividi.php",
  dataType: "json",
  data: {
    res: osrm_result
  },
  success: function(data, textStatus, jqXHR) {
    alert("ciaociao");
    window.open("https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2F52.16.81.189%2Findex_gen.html&src=sdkpreparse");
  }
});

这会触发错误:Url太长了 我怎么能纠正这个让它发挥作用

1 个答案:

答案 0 :(得分:0)

jQuery使用的默认方法是GET,它具有有限的数据长度, 尝试通过POST发送数据(您当然应该相应地更新condividi.php以提供POST请求):

$.ajax({
  type: "POST",
  url: "/condividi.php",
  dataType: "json",
  data: {
    res: osrm_result
  },
  success: function(data, textStatus, jqXHR) {
    alert("ciaociao");
    window.open("https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2F52.16.81.189%2Findex_gen.html&src=sdkpreparse");
  }
});