The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End HTML Element from GET Request Reply To: HTML Element from GET Request


Couple things:

1) You’re not “inserting an HTML element dynamically” – at least, not in the code you posted. If you are subsequently using user-provided values as HTML output, then, yes, you should be careful.

2) The innerHTML you are submitting should be (probably “needs to be”) url-encoded before being sent. Further, I would suggest using the POST method instead of GET.

3) If you are expecting the string you submit to be available to your PHP script (as implied by your $text = $_GET['element'] line), you need to understand how your script is going to execute – PHP and Javascript cannot interact directly, no matter what order the commands are written in.

… PHP happens first, on your server. It sends its output to the browser and then shuts down.

… Javascript (HTML, happens later, on the user’s browser. It has no idea that any such thing as “PHP” even exists. When you make your ajax request, the current script execution (the one we’re discussing right now) will be long gone. /script.php will run again, under a new request.

. – – – – – – – – – – – – – – – – – – – – – – – –

Now, as for helping you out, we would need to know more about what you are trying to do.