• Resolved freelanx

    (@freelanx)


    I have a plugin that insert a form to make an AJAX POST request through an API and show result in same page without changing URL. What I need is to use this form in two pages (home and other page call explore) and add the possibility to make request using the URL.

    When user is in home page use this form to redirect to website.com/explore/parameter1/parameter2/… and show the query. When user is in website.com/explore show the page without any result and search form at top.

    I have been searching a lot trying to find an answer to what is the best method to use but I could not find anything clear. Some method to use can be (maybe they are absurd):

    – In home use normal PHP GET request (by default plugin use POST, I am not sure why, maybe because it request an access token to access to the API) and redirect to explore page with parameters in URL. In explore use the same form fields but using AJAX to make the request in order to not refresh the page and update URL through Javascript.

    – Use the same AJAX form in both pages to update the URL, take parameters from this new URL and make the query using them. After, create a rule to redirect all the pages with the format webiste.com/explore/* to a specific page without modifying the URL (if it is possible).

    Right now, I am a bit lost and any help will be welcome because the more I study, the more I get lost. It seems that after this, it will come the cache problem….

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    For specific advice, I recommend asking in the dedicated support forum of the plugin. I can offer some general observations you might find helpful.

    POST method is usually preferable for submitting forms with any volume of data. GET requests are limited in the amount of data transmitted and the data is more readily visible to prying eyes. There’s no reason you couldn’t POST to get to a new response page.

    To submit to a new page, the form tag’s action attribute needs to be set to the new destination page which will process the request. You will not need the current Ajax script that normally handles Ajax requests and responses, but there could be other UI elements the script is used for which you might want to remain.

    You can prevent the response page from being cached by sending a Cache-Control header with an appropriate directive like max-age=0

    Thread Starter freelanx

    (@freelanx)

    Thank you @bcworkz

    Problem is solved ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘AJAX form show results in other page’ is closed to new replies.