I've got some javascript which uses AJAX to get the output of a php file.
I've been using document.write(data) to show the content which works fine when it's just the script, but when I incorporate the script into wordpress through the header.php, the script works ok except for document.write().
Instead of showing the content received from the AJAX it just reloads the wordpress page.
How can I get around this? I don't mind loading the result in a fresh tab if I an do that and if it helps.
Rather than using document.write
, what you really want to do is append your content to a specific element within the body. You can do this very easily through jQuery:
jQuery('#containerId').append('Content I'd like to add to the page.');