Coder Social home page Coder Social logo

Comments (2)

youtux avatar youtux commented on August 25, 2024

Have you tried encodeURIComponent?

directionUrl+="&origin="+lat+","+long+"&destination="+encodeURIComponent(placeSubtitle);

from pebblejs.

Meiguro avatar Meiguro commented on August 25, 2024

Thanks for reporting this issue! It seems the double quotes causes the URL to be invalid on iOS. The full error is "Invalid URL" (the exception message isn't being shown, but that has been fixed). It looks like a problem with the XMLHTTPRequest object that is provided by the included iOS JavaScript VM. Other browsers, including desktop Safari, have no problem with the double quotes. I hesitate to encode the URI for the user especially since ajax has never done so, and no other xhr library does so. But I may look into doing limited encoding if it doesn't break anything that wasn't expecting encoding in the first place, for example on Android if the same URL is valid there.

In the meantime, you can use encodeURIComponent as youtux outlined, or encodeURI on the entire url before being given to ajax. You can also define your GET parameters in an object and use ajax.formify to encode them. For example:

var params = {
  key: API_KEY,
  origin: lat + ',' + long,
  destination: '"' + placeSubtitle + '"'
};

ajax(
  {
    url: 'https://maps.googleapis.com/maps/api/directions/json?' + ajax.formify(params),
    type: 'json'
  },
  function success(data, status) {
     console.log('Success: ' + status);
  },
  function failure(error, status) {
     console.log('Error: ' + status + ' ' + error);
  }
);

I changed the url to https, but I'm not sure if that works. I would hope it does.

from pebblejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.