mardi 28 juillet 2015

Removing Url and Include Id using Regex and Jquery

I am new to Regex and my question is how can i include the ID from the url and remove it using Regex? because as of now , It only removes the actionMe=reload&Id= but the Id still return so after removing it and replacing with new Url, the old id is still included plus the new ID,

Example, Before removing and replacing the Url:

http://localhost:2216/Main/WorkerPage?workerId=10&actionMe=reload&Id=15

And After Removing and replacing the url , it goes like this:

http://localhost:2216/Main/WorkerPage?workerId=10&actionMe=reload&Id=1615

This is my Code Snippet:

var sss = $("#Id").val();
if (window.location.href.indexOf("&actionMe=reload&Id=") > -1) {
                    var regex = /(\&|&)actionMe=reload&Id=/;
                    var location = window.location.href;
                    if (regex.test(location)) {
                        window.location = location.replace(regex, "&actionMe=reload&Id=" + sss)
                    }

                }

Thanks for Answering guys:)

Aucun commentaire:

Enregistrer un commentaire