首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

extjs不能发送ajax请求,本人生手,求大神指点,代码如下

2013-07-01 
extjs不能发送ajax请求,本人新手,求大神指点,代码如下。本帖最后由 showbo 于 2013-05-27 13:50:52 编辑htm

extjs不能发送ajax请求,本人新手,求大神指点,代码如下。
本帖最后由 showbo 于 2013-05-27 13:50:52 编辑 html代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>lo.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
<script type="text/javascript"src="extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script type="text/javascript" charset="gbk" src="ceshi.js"></script>

  </head>
  
  <body>
  用户名: <input type="text" id="uname" >
  密码:<input type="text" id="upass">
  <input type="button" value="提交" id="tj">
  </body>
</html>


js代码。。。
/**
 * 
 */
Ext.onReady(function(){
alert("ok");

Ext.get('tj').on("click",function(){
/*alert("ok");*/

Ext.Ajax.request({

url:"http://127.0.0.1:8080/ext/hello",
method:'POST',
params:{
uname:Ext.getDom('uname').value,
upass:Ext.getDom('upass').value
},
success:function(resp){
alert(resp.responseText);
}
});




});


});


servelet代码:

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class hello extends HttpServlet {

/**
 * Constructor of the object.
 */
public hello() {
super();
}

/**
 * Destruction of the servlet. <br>
 */
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
 * The doGet method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to get.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {


PrintWriter out = response.getWriter();

System.out.println("你好");
out.print("success");
out.flush();
out.close();
}

/**
 * The doPost method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();
System.out.println("你好!");out.print("success");
out.flush();
out.close();
}

/**
 * Initialization of the servlet. <br>
 *
 * @throws ServletException if an error occurs
 */
public void init() throws ServletException {
// Put your code here
}

}

Ext?JS Ajax
[解决办法]
你按照我1#的增加了failure回调了没有了。。看输出什么错误。。

自己用firefox+firebug或者chrome的开发工具看下报什么错误。
[解决办法]
url 改成 hello ,试试

热点排行