Ajax http.responseText URL vs text

时间:2011-07-08 00:37:49

标签: php ajax httpresponse

是否可以选择从使用ajax调用的PHP脚本返回的响应。可以这样说,而不是找回脚本编写的内容,而不是将整个脚本视为URL并将其作为响应?

我正在调用这样的PHP脚本。

<script type="text/javascript">
    var http = false;
    if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      http = new XMLHttpRequest();
    }
    function LoadCalendar() {
      http.abort();
      http.open("GET", "luxcal/index.php?cP=2", true);
      http.onreadystatechange=function() {
        if(http.readyState == 4) {
          /* document.getElementById('litcal').src = http.responseText; */
          document.getElementById('litcal').innerHTML = http.responseText;
        }
      }
      http.send(null);
    }
</script>

在div innerHTML中加载PHP脚本响应有效。我宁愿在iframe中加载响应。 http对象是否有选项来获取URL响应,例如http.responseURL?然后我可以做document.getElementById('litcal').src = http.responseURL。感谢。

1 个答案:

答案 0 :(得分:0)

如果要在iframe中加载响应,只需在不使用AJAX的情况下在HTML中执行

<强> HTML

<iframe id="litcal"></iframe>

<强>的Javascript

<script type="text/javascript">
  document.getElementById('litcal').src = 'luxcal/index.php?cP=2';
</script>