Sencha Touch -与服务器端通信。

服务器端:Servlet代码

 protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/xml;charset=UTF-8");
        StringBuffer jb = new StringBuffer();
        String line = null;
        try {
            BufferedReader reader = request.getReader();
            while ((line = reader.readLine()) != null)
                jb.append(line);
        } catch (Exception e) {

        }
        System.out.println("req.getReader() " + new String(jb));
        String out = "[{\"id\":100 ,\"sympname\": \"新症状1\" , \"belongs\": \"alternative\" },{\"id\":101 ,\"sympname\": \"新症状2\" , \"belongs\": \"alternative\" }]";
        PrintWriter pw = response.getWriter();
        pw.write(out);
    }

 

前端Sencha Touch Js:

var jData = {
 'records' : [{
    name : 'my record'
   }, {
    name : 'another record'
   }]
};
Ext.Ajax.request({
   url : 'http://10.39.62.77:8080/TestAndroid/android',
   method : 'POST',
   jsonData : jData,
   success : function(response, opts) {
    alert(response.responseText);
      var obj = Ext.decode(response.responseText); 
      alert(obj);
                     console.dir(obj); 

   },
   failure : function(response, opts) {
      alert("error");
   }
  });
res/xml/config.xml加入配置:

<access origin="http://10.39.62.77*"/>

 

 

你可能感兴趣的:(Sencha Touch -与服务器端通信。)