简体   繁体   中英

Return data to the original webpage after a series of back and forth requests

I have a website structured like so:

"Client side": HTML / CSS / Javascript
"Server side": PHP

Client side, when a user pushes a button, he's redirected to a page ( bold because the click action does not trigger a php script, the redirection itself does with window.open("https://...../, '_self'); ) that toggles a series of scripts back and forth to get, check, and validate data from various other websites and storing some of them in my DB.

Once this is all done, at the end of my last PHP script i need to redirect my user to the original webpage with a bunch of divs and spans and whatsnot updated with the data retrieved.

Typically at the end i'd have this

header( "Location: $originalURL" );  

How should i redirect my user while sending back data to the original webpage all the data i need to update my html elements?
Through a POST request?
By doing something similar to this:
header( "Location: $originalURL/?data1:$data1&data2:$data2" ); ?
which i would really much avoid not only for its uglyness or unaesthetical aspect, but most of all for the process to be entirely transparant from the user point of view.

EDIT (to explain the 'flow'):

  1. mywebsite.com/mypage/index.**html**
  2. js click function ( window.open(mywebsite.come/mypage/processes/index.php) )
  3. series of back and forths between external URLs to get data
  4. last call back to my domain mywebsite.com/mypage/stepX/index.**php**
  5. redirection to mywebsite.com/mypage/index.**html**
  6. mywebsite.com/mypage/index.**html** gets the data from step 5 and updates html elements via its script.js

And i'm stuck at step6. How does my script.js get all the new data directly with the redirection from my server-side PHP script?

You shouldn't use header(location:) here because it is only a way to force browsers to brutally get to a page.

You need to use require_once() function which is meant to include a PHP file into another. In that way, you would transform your HTML page into a PHP file and you'll be able to access to variables from the file you required.

Passing an HTML file into PHP file is pretty straightforward, it will allow you to transform your PHP variables into JS variables .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM