fire external script background with js?

131 views Asked by At

is it possible to fire the execution of a script in the background via click?
I am within a CMS/CRM and want to trigger an external file to load when clicking on a certain link within the CMS/CRM.

e.g. activate the php.mailer to send an email.

It seems to be a security issue when using (cross domain vulnerability?)

foobar.onload()

and if it weren't, it would not execute the file in the background. I have seen that it was solved in python using with

subprocessor()

.

The external script would be on my domain though and not touch the CMS / CRM.
Any ideas?

2

There are 2 answers

1
eroak On BEST ANSWER

In JavaScript you can't access to the filesystem, but you can use ajax to request some url with differents methods (GET, POST...).

The script you called from the url can execute a function to send an email if you want.

If you know jQuery, you can do something like that in JavaScript

$.get("myScript.php");

And in your myScript.php file :

mail('[email protected]', 'Hello', 'Cool !');

And if your php script is not on the same domain, you should check Access-Control-Allow-Origin header that allow your client (the browser which execute the ajax script) to call the remote php script

0
Richard On

You could have your click event handler make an AJAX request. For example:

myButton.onclick = function (e)
{
    // Make an AJAX request with jQuery
    $.get('/ajax/getFoo.php', function (data)
    {
        // This runs when the AJAX call returns
    });
}

Alternatively, you might look at the jQuery .load() function too:

http://api.jquery.com/load/