1

I am trying to send my HTTP response to a new web page so that I can display the details of my response on that web page. My javascript currently redirects the page to a new page but I can't seem to get my response passed over.

This is what my Javascript currently looks like enter image description here

What would the best way of doing this?

Edward Muldrew
  • 253
  • 1
  • 6
  • 20
  • Apart from query strings (which would get messy when storing the response), I don't think you can really do anything without a backend. If the response is small (like a boolean or something) just append a query string to your `location.href` value. – Adrian Dec 31 '19 at 10:42
  • @Adriani6 I have a backend which I control, what would you suggest doing for this? Or if I just sent parameters through the redirect, I could make the call that way? – Edward Muldrew Dec 31 '19 at 10:43
  • Which backend? I think your logic is a bit flawed here. What's stopping you from putting an anchor tag and doing the search server side and redirecting the user to the same location the response is doing? You'd save a lot of trouble yourself. Right now you want to pass data about a bit too much. – Adrian Dec 31 '19 at 10:46

1 Answers1

0

In searchAnimalCharity you're performing a GET request, not a POST one. With this in mind, we have to split this in two parts.

First one: Do a POST request sending your desired data (Javascript).

Second one: Go to your localhost server and prepare a PHP file that gets that request and then redirects the user to the other page you want, passing with it the POST parameters.

You have an example here.

Edit: In case you want to pass the response from the javascript requested URL to the third one, you can pass custom parameters from your PHP to that third page.

Hope this helps you!

Jorge C.M
  • 375
  • 3
  • 11
  • 1
    Why does it need to be a `POST` request? Why do you assume he's using PHP? Why would you pass data back and forth if he controls the backend and all he does is use the response to create the next page? – Adrian Dec 31 '19 at 10:47
  • I think that Edward is the one who has to tell me those things in case it's needed, so I can then update my answer accordingly. No need to be that rude. – Jorge C.M Dec 31 '19 at 10:51
  • 1
    I'm not rude, it's just questions - no needs to take them offensively. :) If we're posting answers they're answers to the question, right now, you're guessing the answer ;) – Adrian Dec 31 '19 at 10:52