newbie
newbie

Reputation: 14950

Passing variables in URL

I have an address book widget that shows if there are contents. If there are no contents, an add button will show up. Upon pressing the add button, it will redirect to another page which will show the form.

The initial design of my website is as follows:

  1. When the user click the add button, it will direct to a page using javascript function:

    document.location.href="address?addOnly=true";
    
  2. The form will display.

  3. If successful, there are $.post that will change the div only that will enable user to do CRUD in the address book.

The problem with the variable inside the url which is address?addOnly=true is that when the user refresh it, it will always shows the add form.

That's why i've decided to hide the implementation using $.post

$.post('address', {"listEmty":true}, function (data) {
  window.location = "address";
});

The problem with this is that it can't pass the variable at all.

My questions are:

  1. How to handle the page refresh if using the get method, which passes the paramater in the URL,
  2. Are there anyways in javascript/jquery to pass the variable using post method then refresh the page?

Thank you.

Upvotes: 0

Views: 173

Answers (1)

Ariel
Ariel

Reputation: 26753

<FORM method="post" action="address" id="refresh" style="display: none;">
  <DIV>
    <INPUT type="hidden" name="addOnly" value="true">
  </DIV>
</FORM>
<SCRIPT type="text/javascript">
  document.getElementById('refresh').submit();
</SCRIPT>

What this does is create an invisible form, then immediately submits it. You can of course call the submit from within your other javascript code.

Upvotes: 1

Related Questions