25-03-2011, 13:17
|
|
|
חבר מתאריך: 06.05.07
הודעות: 7
|
|
קבלת והחזרת ערך אל ומשרת אחר, באמצעות ajax
אז ככה,
אני מנסה להתחבר לשרת מסויים משרת אחר ולקבל ממנו מידע ואני לא מצליח
המטרה היא לשלוח פרמטרים לשרת מרוחק ולהחזיר אותם מבלי לעבור דף,
ניסיתי את השיטה הבאה:
קוד PHP:
<script language=javascript> function ahah(url, target) { document.getElementById(target).innerHTML = ''; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } if (req != undefined) { req.onreadystatechange = function() {ahahDone(url, target);}; req.open("GET", url, true); req.send(""); } } function ahahDone(url, target) { if (req.readyState == 4) { // only if req is "loaded" if (req.status == 200) { // only if "OK" document.getElementById(target).innerHTML = req.responseText; } else { document.getElementById(target).innerHTML="\n"+ req.status + "\n" +req.statusText; } } } function ahah2(url, target) { document.getElementById(target).innerHTML = ''; if (window.XMLHttpRequest) { req2 = new XMLHttpRequest(); } else if (window.ActiveXObject) { req2 = new ActiveXObject("Microsoft.XMLHTTP"); } if (req2 != undefined) { req2.onreadystatechange = function() {ahahDone2(url, target);}; req2.open("GET", url, true); req2.send(""); } } function ahahDone2(url, target) { if (req2.readyState == 4) { // only if req is "loaded" if (req2.status == 200) { // only if "OK" document.getElementById(target).innerHTML = req2.responseText; } else { document.getElementById(target).innerHTML="\n"+ req2.status + "\n" +req.statusText; } } } function load(name, div) { ahah(name,div); return false; } function load2(name, div) { ahah2(name,div); return false; } function init() { load('http://*****.co.il/re.php?t=1000000&s=420','div1'); } </script> <body onload="init();"> <div id=div1 name=div1> </div> <div id=div2 name=div2> </div>
השתמשתי ב
JS
אבל זה מביא לי הודעת שגיאה של
Access denied
וזה ברור
למישהו יש רעיון אחר איך אני יכול לעשות את זה?
בלי שהוא יתן לי שגיאה
,
תודה מראש
|