An initial understanding of Ajax proxy Proxies

Source: Internet
Author: User

This is just a preliminary understanding of proxy, analysis of an example

Let's look at a JS file first: proxy.js

  (function () {<span style= "white-space:pre" > </span> ext.onready (function () { <span style= " White-space:pre "> </span>ext.define (" Person ", {    Extend: ' Ext.data.Model ',       Fields: [        {name: ' name ', type: ' Auto '},         {name: ' Age ',  type: ' int '},         {name: ' email ', type: ' Auto '}    ],     proxy:{ <span sty le= "White-space:pre" > </span>type: ' Ajax ',  <span style= ' White-space:pre ' > </span>url: '
Proxy.jsp '    }  <span style= "White-space:pre" > </span>});
 <span style= "White-space:pre" > </span> var p = Ext.ModelManager.getModel (' person ');     P.load (1, {    scope:this,     failure:function (record, operation) {    &N Bsp  //do Something if the load failed    },     success:function (recoRd, Operation) {       //do something if the load succeeded     <span style= "White-spac
E:pre "> </span>alert (record.data.name);          callback:function (record, operation) {       //do something WH
Ether the load succeeded or failed    }); <span style= "White-space:pre" > </span>})  }) ();


Then look at a JSP file: proxy.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<% response.getwriter
(). Write ("{name: ' uppcat.com ', Age:16,email:" Wfc@163.com "}");
%>

 
This JSP actually provides data for the foreground, which can be either a JSON string for direct writing or a value taken out of the database. Be sure to pay attention to his writing format.


Load Proxy.js on the front page

<script type= "Text/javascript" src= "Proxy.js" >
    </script>


Analysis, Proxy.js is divided into three sections: 1) Create a person class

Ext.define ("person", {

2) Examples of classes: var p = Ext.ModelManager.getModel (' person ');

3) Call the Load () method after creating the instance

var p = Ext.ModelManager.getModel (' person ');

Let's take a look at this function load ():

P.load (1, {
Scope:this,
Failure:function (record, operation) {
Do something if the load failed
},
Success:function (record, operation) {
Do something if the load succeeded
alert (record.data.age);
},
Callback:function (record, operation) {
Do something whether the load succeeded or failed
}


We based

Model creates the class, and then we use Ext.ModelManager.getModel (' person '), create the corresponding instance, view the model class, and use the load () method to display the data
This load is a bit of a point: we may not understand what recod is, or what other functions are, and we need to learn to debug in the browser.
In the future we can be in JS in charge of obtaining data OK,



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.