javascript - Getting the URL in jQuery and creating a post link ajax -
i have url looks like....
/page/sub/25/ --- edit page id @% /page/sub ---new page has no id the last part of url id (if not new page there not id).
i need in jquery last part of url , send post. example...
$.ajax( { type: "post", url: urlvar, data: "site="+encodeuricomponent(json.stringify(site)), datatype: "json", }, where urlvar if has id be
page/update/25 and if not
/page/update how can generate urlvar based on current url this?
try this:
var href = window.location.href; var val = href.substr(href.lastindexof('sub') + 4).replace('/', ''); var urlvar = ''; if (val !== '') urlvar = 'page/update/' + val; else urlvar = '/page/update'; alert(urlvar);
Comments
Post a Comment