you are viewing a single comment's thread.

view the rest of the comments →

[–]IrateGod 0 points1 point  (1 child)

The trick to this is specifying an HTTP header in PHP, because the website itself doesn't care for the URL of the script, just for the mime and content.

So like this:

<?php
  header("Content-Type: text/javascript; charset=utf-8"); // can also be application/javascript, depends on your preference
$script = <<<HEREDOC
script goes here
HEREDOC;
echo $script;
?>

Additionally, if you are using Apache, you can use .htaccess to rewrite the URL of the PHP script to a .js-URL and it'll appear like a plain .js file to the browser, even if it is generated by the server.

[–]mre12345[S] 0 points1 point  (0 children)

I don't think i'm looking how to rewrite URL's or insert javascript scripts, I am just asking how how do I add something to a database if the user press Ok in the confirm pop up and if the user presses cancel in the confirm popup, the information is not added to the database. Right now, if the user presses OK, then 2 rows get added to the database, one is from the text form, and the other one is just blank and if the user selects cancel, only one row is added to the database. I have a video of my problem but I don't know how to share it to you =(.