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
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
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');
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.