0
How can I post data in html without open the php-file?
I tried to write an own php script which gets a string over the post method in html forms, but when I run it with action="file.php", the localhost displays the file.php file. Why?
9 Réponses
+ 14
An XHR request. It's a background form that does not redirect.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
Note that you would have to resolve the data manually like:
http://server.com/page.php?user=abc&pass=def
+ 15
There's probably something equivalent for php but i think you'd need to do it with js on this case. (the only way to grab data and send to server are html forms and js xhrs, php can do requests but cant get the data by itself)
+ 13
This would just redirect you back, might not be the best experience for the user but works fine.
+ 11
Forms are supposed to redirect the data you input to the action page, alternatively, you could cast an XHR or change the redirection target of the form.
+ 3
it should as it passes the data to it. you can put a redirect to redirect to the page you were on
+ 3
normally nice as you get to make a file do a piece of logic
else, you can post to the file itself
https://stackoverflow.com/questions/5826784/how-do-i-make-a-php-form-that-submits-to-self
+ 2
Thank you for the quick answers. I googled it and came to header("Location: file.html);
+ 1
What could be a better solution?
Or what exactly is an XHR? Because when I change the redirection target, the data isn't sent to the php-script
0
Can I somehow use XMLhttpRequest directly in php or do I have to use js?