Hi,
In order to satisfy the cross-domain security limitations in javascript I've written a simple loader in php for an external calendar service.

My question is, what is the best way of adding this code for use in drupal. For testing purposes I'm currently supplying the absolute path to the php file in my javascript code.
Ideally I would like to not do this for security reasons.

Thanks.
Alex

Comments

Jaypan’s picture

You should create a module and do the following:

1) Implement hook_menu() to create a callback path
2) On the page that the script will be added, you should pass some javascript settings to your script. One should be your callback path, the other should be a token generated with drupal_get_token()
3) Use the callback path that you passed within your script. Make sure that your ajax requests to the server also pass the token you passed
4) Check the value of the token in your callback function to ensure that it is the same

Read more here: https://drupal.org/node/756722