0

I'm using ajax and I'd like to somehow turn the current page's url into a data object used for ajax method. I'm using window.location.search to get the current url of the page and I'm not sure the best way to turn the url into a data object used for ajax.

URL (window.location.search):

?pickup-location=Orlando+Intl+Airport+%28MCO%29%2C+FL&dropoff-location=&pickup-date=07%2F16%2F2018&pickup-time=12%3A00&dropoff-date=07%2F17%2F2018&dropoff-time=12%3A00&discount-code-company=&pagination=1

End Goal:

data: {
    pickup-location: "Orlando+Intl+Airport",
    .... etc ...
    pagination: page
},
Michael
  • 403
  • 1
  • 9
  • 28
  • Are you asking for a library or if a JavaScript function can do this? – zero298 Jul 02 '18 at 18:35
  • Possible duplicate of [How can I get query string values in JavaScript?](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – zero298 Jul 02 '18 at 18:36
  • I'm pretty sure @zero298 is correct there are multiple answers on that post that cover what you need. – Rewire Jul 02 '18 at 18:41
  • doesn't it already work with the query string? Unless you want to transmit it as JSON, the data are transformed into that (URL) format anyways. – Dormilich Jul 03 '18 at 08:09

0 Answers0