当前位置: 动力学知识库 > 问答 > 编程问答 >

Ajax call with native javascript get no response

问题描述:

I have implemented a ajax call with native js to a php file.

How my call work: I hava a script tag to a js.file placed in footer of a drupal7 CMS like this:

<script id="script_dah" type="text/javascript" src="http://mydomain/snippets/snippet.js?community=xy">

This is the content of snippet.js:

function getMembers(){

if ( typeof XMLHttpRequest == 'undefined' )

{

XMLHttpRequest = function ()

{

try

{

return new ActiveXObject( 'Msxml2.XMLHTTP.6.0' );

}

catch ( e ) {}

try

{

return new ActiveXObject( 'Msxml2.XMLHTTP.3.0' );

}

catch ( e ) {}

try

{

return new ActiveXObject( 'Msxml2.XMLHTTP' );

}

catch ( e ) {}

throw new Error( 'This browser does not support XMLHttpRequest.' );

};

}

//Get the community

var selectScript = document.getElementById("script_dah").getAttribute("src");

var community = selectScript.split("=")[1];

//Get the div

var selectDiv = document.getElementById("snippet_dah");

//Send to the server and get the results

var xhReq = new XMLHttpRequest();

xhReq.open("GET", "http://mydomain.com/snippet.php?community="+community, true);

xhReq.send(null);

xhReq.onreadystatechange = function() {

if (xhReq.readyState != 4) { return; }

var serverResponse = xhReq.responseText;

selectDiv.innerHTML= serverResponse;

};

//}

}//End function

setInterval("getMembers()", 10000);

This is my php file:

<?php

echo 'INSIDE';

I am not sure, what the problem is. Is it because of origin policy, or is it because of drupal that block the response?

If i test it with a dummy html on my own domain however it works!

分享给朋友:
您可能感兴趣的文章:
随机阅读: