-5

How can I get the id form this url below using jquery?

http://localhost:8080/moduloESR/actualiza_evento.php?id=1009

I just want to take : 1009

Rizier123
  • 58,877
  • 16
  • 101
  • 156

2 Answers2

1

You don't need jQuery for this. Just create a function like this:

function getParam(name) {
  name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
      results = regex.exec(location.search);
  return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

then call, passing the values you want:

var id = getParam('id');
Thiago Elias
  • 939
  • 1
  • 6
  • 21
-1

A one-liner solution was posted here: How to get URL parameters with Javascript? And I quote:

function getURLParameter(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}

So you can use:

myvar = getURLParameter('myvar');

Or in your case:

id = getURLParameter('id');

jQuery is not required.

Community
  • 1
  • 1
abali96
  • 24
  • 1
  • 5
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Display Name is missing Sep 11 '15 at 17:40
  • Updated the answer to include the most essential parts from the link I had previously. – abali96 Sep 11 '15 at 20:05