How to pass parameter in wordpress url?

How do you pass an array parameter in a .jsp file without having a very long URL?

  • I have to jsp files and I want to pass an array from the first one to the second one. I have this code: (1.jsp) <script> var wordsArr = [red, blue, green, black, white, yellow, orange]; var arrcount = words.length; window.location.replace("2.jsp?words=" + wordsArr + "&count=" + arrcount); the URL becomes "2.jsp?words=red,blue,green,black,white,… Is there another way to make the resulting URL shorter?

  • Answer:

    Technically speaking, you need to use http post instead of http get. Normally that is done with a form, but it can be done entirely in javascript. This keeps the input out of the resulting url. var wordsArr = [red, blue, green, black, white, yellow, orange]; var arrcount = words.length; var myForm = document.createElement("form"); myForm.method="post" ; myForm.action = "2.jsp"; var wordsInput = document.createElement("input") ; wordsInput .setAttribute("name", "words") ; wordsInput .setAttribute("value", wordsArr); myForm.appendChild(wordsInput ) ; var countInput = document.createElement("input") ; countInput .setAttribute("name", "count") ; countInput .setAttribute("value", arrcount); myForm.appendChild(countInput ) ; document.body.appendChild(myForm) ; myForm.submit() ; document.body.removeChild(myForm) ;

chained at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.