至死孤独 2014-12-03 09:18 采纳率: 0%
浏览 1660

关于Ajax 入门一直出错

在客户端页面输入自己的名字,服务端返回‘你好+名字’
执行会有错误提示AjaxGet()函数未定义
我是在VS下开发的给你们贴出目录和源码

HTMLPage.htm是客户端页面,源码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">




<br> var xmlhttp;<br> creatXMLHttpRequest();</p> <pre><code> function ajaxGet() { var s = document.getElementById(&quot;yourname&quot;).value; var url = &quot;Server.aspx?yourname=&quot;+ escape(s); creatXMLHttpRequest(); xmlhttp.onreadystatechange = handleStateChange; xmlhttp.open(&quot;GET&quot;, url, true); xmlhttp.send(null); } function creatXMLHttpRequest() { //在IE下创建XMLHTTPRequest try { xmlhttp = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;); } catch (e) { try { xmlhttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); } catch (oc) { xmlhttp = null; } } //在Mozilla和Safari等非IE浏览器下创建XMLHTTPRequest对象 if (!XMLHttpRequest &amp;&amp; typeof XMLHttpRequest != &quot;undefined&quot;) { xmlhttp = new XMLHttpRequest(); } return xmlhttp; } function handleStateChange(){ //4请求完成加载 if(xmlhttp.readyState == 4){ //200返回完成 if(xmlhttp.status ==200){ var obj=document.getElementById(&quot;userlist&quot;); //获取服务器返回的文本,在页面显示 obj.innerHTML=xmlhttp.responseText; } else{ alert(&quot;请求页面异常&quot;); } } &lt;/script&gt; </code></pre> <p></head><br> <body><br> <div id="userlist"></div><br> <form id="form1" name ="form1" method="get" action=""><br> 姓名:<br> <input type="text" name="yourname" id="yourname" /><br> <input type="button" name="button" id="button" value="确定" onclick="ajaxGet()"/></p> <p></form><br> </body><br> </html></p> <p>客户端Server.aspx源码如下<br> &lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Server.aspx.cs&quot; Inherits=&quot;Server&quot; %&gt;</p> <p>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd%22%3E">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</a></p> <p><html xmlns="http://www.w3.org/1999/xhtml"><br> <head runat="server"><br> <title></title><br> <script runat="server" type="text/C#"><br> protected void Page_Load(object sender, EventArgs e)<br> {<br> string userName = Request.QueryString[&quot;yourname&quot;].ToString().Trim();<br> Response.Charset = &quot;utf-8&quot;; <br> Response.Write(&quot;<h3>你好&quot;+userName+&quot;!</h3>&quot;);<br> }<br><br>



</div>
</form>



  • 写回答

1条回答

  • greatbody 2014-12-03 11:58
    关注

    你还是把代码放到CODE上面吧(code.csdn.net)。

    这代码看起来好吃力。

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮