weixin_33694620 2015-11-27 07:26 采纳率: 0%
浏览 14

Ajax不能正常工作

this is my client side code.The server side php code is simply to echo statement.

function load(){if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari     
    xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.xmlhttp");}
    if(xmlhttp==null)
    { alert ("Your browser does not support XMLHttpRequest!");
        return; }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.write("Received");
            document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET", "http://localhost/tphp.php?", true);/*this works separately*/
    xmlhttp.send();document.write("Sent")}

My html code contains

<h4 id="txtHint">to be replaced</h4>
<input type="button" onclick="load()" value="click" />

My PHP code it contains echo statement.i just want to test it

<?php
echo "It's working";
?>
  • 写回答

2条回答 默认 最新

  • ?Briella 2015-11-27 08:24
    关注

    I am not sure if you can use jQuery, if so please make these things simple:

    $("body").append("Sent<br/>");
    $.get("/tphp.php", function (data) {
      $("body").append("Received: " + data + "<br/>");
    });
    

    Advantages of using jQuery:

    1. Code is simple.
    2. Excellent cross browser support.
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动