Forum Moderators: open
the iframe makes an ajax call to another file http://example.com/ajax.xml
when the submit button on the main page is clicked it calls a function in the iframe and retrieves a value to put in a hidden field in the form.
to get this to work I have to set document.domain="example.com"; in both the main page and the iframe. correct?
well because I have to do that to make them talk to each other the ajax call will not work. Because I am calling an xml page I cannot set javascript document.domain there.
Is there any way you can think of that will allow both the ajax call and the passing of values from iframe on main domain to subdomain to work?
Thank you.
ps. title should read:
using ajax in the iframe and js between iframe and main page
JS:
var js = document.createElement("script");
js.type="text/javascript";
var d = new Date():
var q = encodeURIComponent("some query");
js.src = "update.php?q="+q+"&d="+d.valueOf();
document.appendChild(js);
PHP: (or any other server side language)
$q = $_GET{'q'};
#run some query with $q
$stored result as HTML output or Javascript
echo "newData('HTML Output');".$StoredJavascript;
Now this script can be called as many times as you want. You can send form data via GET, insert/update stuff, then return a success or error message. This will all work accross any domain. Whatever script your server page generates is run right away. It's speed is comparable to the XmlHTTPRequest object.
- JS