Duplicate variable in query string
I am experiencing a strange issue with javascript and firefox 10.0.11. I tested with IE and was unable to reproduce the issue.
I have a link that goes to a page that shows some information about an object. I have added additional functionality to this page using javascript. If javascript is enabled, the binding will be redirected to the javascript function.
<a href="/Comment?id=1186281" onclick="return CommentSubmit(1186281)">Comment</a>
function CommentSubmit(id) {
$("#DynForm").append("<input type='hidden' name='id' value='" + id + "' />");
$("#DynForm").attr("action", "/Comment/Index");
$("#DynForm").submit();
return false;
};
As you can see, javascript is inserting a hidden input tag with a key value. The non-javascript version works fine, but I am experiencing some javascript issues. The first time the button is pressed, Comment
any item is penalized. If I hit, then click any link Comment
, the page appears as if I clicked on the first link again. On checking, I noticed that the URL parameters "add up" for each subsequent "Back" and 'Click'
/Comment?id=1
/Comment?id=1&id=2
/Comment?id=1&id=2&id=3
If I navigate to the page again (without going back) the first link works again and then starts this weird behavior. Looking at the source of the page after clicking a few links, I don't see any new fields hidden
that would add these additional options. Is this a known issue? How can I debug this and fix it?
source to share
This is not a bug, this is a feature :)
Your browser is caching the page, so when you return you don't refresh it, you return to it as it is, i.e. with hidden input field.
All you have to do is remove this field before adding it again.
function CommentSubmit(id) {
$("input[name=id]").remove();
$("#DynForm").append("<input type='hidden' name='id' value='" + id + "' />");
$("#DynForm").attr("action", "/Comment/Index");
$("#DynForm").submit();
return false;
};
source to share