XMLHttpRequest中的javascript不起作用

时间:2014-09-03 14:33:20

标签: javascript php ajax xmlhttprequest

您好,并提前感谢您的关注和帮助。

我需要从ajax调用的div内部运行javascript代码(我使用XMLHttpRequest但不是必需的)

我的html代码如下(我需要将javascript执行到 for_inclusion div):

<html>
    <head><script type='text/javascript' src='ensayo.js'></script></head>
    <body>
        Normal text<br />
        <button onClick="llamarProceso('ensayo.php', 'for_inclusion', 'The Message');">
            include new java
        </button>
        <br />
        <div id='for_inclusion'></div>
    </body>
</html>

ensayo.js的Javascript代码是:

//----------------------------------------------------------------------
function nuevoAjax(){
    var xmlhttp=false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}
//----------------------------------------------------------------------
function llamarProceso(script, division, data) {
    contenedor = document.getElementById(division);
    ajax=nuevoAjax();
    ajax.open("POST", script, true);
    ajax.onreadystatechange=function() {
        if (ajax.readyState==4) {
            contenedor.innerHTML = ajax.responseText;
        }
    }
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("data="+data)
}

最后php脚本是:

<?php
var_export($_REQUEST);
print "<script type='text/javascript'>alert('".$_REQUEST['data']."');</script>";
?>

点击按钮后我需要收到“消息”警告,但这不会发生。

php正确写入var_export指令,javascript代码正确写入但不采取任何操作。

也许我需要使用jquery.ajax或类似的东西来改变整个ensayo.js ...任何想法

0 个答案:

没有答案