1

Im writing this code for save an url in a file txt, that i will use too pass after the same for invoke the button share. my problem come when i use this code

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

this trigger the error: Url too long how i can correct this to make it work

Carsten Løvbo Andersen
  • 26,637
  • 10
  • 47
  • 77

1 Answers1

0

the default method which jQuery uses is GET which has limited data length, try sending the data by POST (you should of course update the condividi.php accordingly to serve the POST request):

$.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");
  }
});
Picard
  • 3,745
  • 3
  • 41
  • 50
  • you can up-vote this answer if it helped so in the future, people are directed to the accepted answer – Rotimi Apr 12 '17 at 09:25