lynxus Posted December 1, 2008 Share Posted December 1, 2008 Hi Guys, I run a service that requires people put a login form on their website with afew custom values like x = Mypage y = Somevalue. However this code gets updated fairly often so i want to try and dynamiccaly insert this into the other websites. So lets say , Joeblogss visits, Mynewsite.com and it has some javascript that runs off to my server and reads getdata.php?id=1&blaa=2 that php script will echo some html code for a form with its custom information in it and then when mynewsite.com finishes loading it will have the login form on it where it got the dynamic html from my server. I managed this below, HOWEVER It only works on the test.html page on the same server as the .php file. HOW on earth do i get round this? Im assuming its a problem with XSS. There must be a way to do this.. Surely? OK ive managed this, but it doesnt work when i run this script on another machine other than the one with the PHP script on.. Any ideas how i can get round this ? This has been driving me mad for about 3 months now and really starting to bugger up my plans. Essentially what im trying to do is have a user put some small code on their site with someting like ID=1 in their code. When a user visits it will goto my php script on another server. the script will then output some html that gets placed in the div on the end users machine. For the life of me i cant get this working on any other machine than the one that the php script is actually on. <html> <body onload="ajaxContentUpper();"> <script language="javascript" type="text/javascript"> <!-- function ajaxContentUpper() { var ajaxRequest; try { // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e) { // Internet Explorer Browsers try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function() { if(ajaxRequest.readyState == 4) { var ajaxDisplay = document.getElementById('TestContent'); var result = ajaxRequest.responseText; if (result == 'expired') { window.location = '/'; } else { ajaxDisplay.innerHTML = result; reSizeLeftRight(); } } } ajaxRequest.open("GET", "http://212.125.94.168/ajax/gimme.php", true); ajaxRequest.send(null); } //--> </script> <div id = "TestContent"> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 1, 2008 Share Posted December 1, 2008 Maybe I'm not understanding this 100%. But, I just took the code you posted and created a new file on my desktop. When I run the page in a browser, the word "Hello" is displayed. Since that text does not appear in the code I assume that is the text returned by the AJAX call and populated into the DIV. Although there is an error on this line reSizeLeftRight(); because that function is not within the code you provided. I don't see any parameters being used in that code such as you explained, so I'm not sure what should or should not be happening here. If the remote sites are going to include the entire AJAX code, it should work fine. But, you cannot include external javascript files from remote sites. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted December 2, 2008 Share Posted December 2, 2008 Ajax can only access pages on the local server. If you want to access remote pages, use Ajax to call a local PHP page and have that PHP page fopen or CURL the remote page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.