Nishita Patel Nishita Patel - 5 months ago 18
Ajax Question

how can i get current page url id from ajax

i want to fetch id from url if my url is like this: mydomain.com/Login/update/29/2

$:

function itemSubmit(){ var id1 = "<?php echo $_GET['item_id']; ?>";
alert(id1);$.ajax({ type: "POST", url: "<?php echo SITE_ROOT;?>Login/update_data"+id1, dataType: "json", }); }

Answer

Try this

var url = document.URL;
var stuff = url.split('/');
var id1 = stuff[stuff.length-2];
var id2 = stuff[stuff.length-1];
Comments