Specific embodiment
The data request method of the embodiment of the present application can be applied to WEB request, such as scene shown in FIG. 1, WEB visitor
Family end 11 is to 12 request data of WEB server.Wherein, WEB client side 11 can be at terminal (for example, PC, mobile terminal etc.)
Some webpage run on browser, browser need to request to WEB server 12 normally when parsing executes the web page code
Some data required for webpage are run, the data request method of the application can be used, at this time to obtain these data.
Fig. 2 illustrates the process of the data request method of client executing, as shown in Fig. 2, may include:
201, request mark and respectively request end corresponding with the request mark and agent side are generated;
202, target data required for the request end is requested to server by the agent side;
203, request identifies corresponding agent side and obtains the target data that the server returns, and is identified by the request
Corresponding request end uses the target data performance objective business.
In order to enable this method process is easier to understand, referring initially to the example of Fig. 3, Fig. 3 illustrates the embodiment of the present application
Data request method overall framework.One WEB page is when operating normally, wherein might have multiple display portion needs
It is just able to achieve the normal display page to server request data, can be indicated with " event A " wherein once to server number of request
According to event A is being got after the data that server is requested, and the data will be used to execute data processing stream as defined in event A
Journey, to show the corresponding page in the part;Another time can be indicated with " event B " to server request data, equally will use
Data execute process flow as defined in event B.It is, of course, also possible to which the same WEB page can wrap there are event C, event D etc.
The event repeatedly to server request data is included, the present embodiment respectively indicates number different in WEB page with different " event "
According to request, only it is exemplary in Fig. 3 for two kinds of events of display.Also, event A and event B use the present embodiment
Data request method obtains data to server.
By taking event A therein as an example, event A is briefly described, data are obtained by server and handle the process of data, tying
Fig. 3 is closed to describe to be involved in following several concepts when the process:
Agent side: it for example, the agent side can be a hiding empty IFRAME (frame), hides and is seen in the page
Less than the IFRAME, sky is that any request or processing is not carried out in the IFRAME itself, and it is fixed only to execute webpage design personnel
Logic inside the IFRAME of justice.In the present embodiment, it when using IFRAME as agent side, is equivalent in a WEB page
In be provided with a nested page, that is, IFRAME, but the IFRAME is an independent running environment, is exclusively used in as to clothes
Business device request page data (are equivalent to the middle-agent of request data in WEB page, rather than go server to ask by page itself
Seek data).
" agent side " is arranged in WEB page in the present embodiment, mainly considers all to be usually in conventional manner by WEB page
Itself is to server request data, and for the corresponding multiple events of multiple request of data in the page, WEB page will be responsible for differentiation
The corresponding relationship of response data and request event that server returns, such as the page can create multiple functions (different function
Name, respectively corresponds different event), that is, the event for needing to do page entirety is distinguished, very cumbersome;And after using " agent side ", such as
Described in upper, it is the dedicated agent side of some event, for requesting the correspondence that each agent side, which is an independent running environment,
The data of event, even if each agent side all uses identical function (for example being all define ()), the agent side of the page overall situation
Between will not generate conflict, and the present embodiment only need by agent side respectively with each secondary event binding, for example, by using ID
It distinguishes, subsequent embodiment will describe.
Request end: request end is in WEB page for request data and using the module of the data, such as the institute in Fig. 3
" second function " shown is properly termed as request end, and the explanation of the function may refer to following.
First function: shown in Figure 3, first function can be " overall situation function of IFRAME ", and agent side is to service
Device request data, server can return to an executable script to agent side, include the event of agent side request in the script
Data, agent side can execute the data that the script gets server return by first function.Also, the first function is also
The data that can be will acquire are transferred to request end, such as the second function being transmitted in Fig. 3.It can be seen that the first function is
For getting server returned data.
Second function: the second function can be " overall situation function of WEB page ", be used primarily for agent side acquisition
The data arrived, and the corresponding call back function of event is called, the process flow as defined in call back function to data is executed, with this reality
Business processing as defined in existing event, the corresponding page of display event.
Call back function: the call back function is mainly used for the data for defining how to get using agent side, that is, uses data
The processing done;And above-mentioned second function is to call the call back function, executes processing as defined in the call back function, to complete
Use to data.
Pass through Fig. 3 and above-mentioned conceptual description, it will be appreciated that event obtain data treatment process, i.e., from agent side to
Server request data simultaneously receives data, then calls call back function by second function, and execute the process flow of call back function,
Complete use of the event to data.
On the basis of above-mentioned Fig. 3 framework, the process of Fig. 2 is described as follows:
Process shown in Fig. 2 is WEB page when every secondary request data, the process that will be executed, still
As shown in connection with fig. 3, when WEB page will execute the corresponding request of data of event A, then start to execute Fig. 2 process;Work as WEB page
When executing the corresponding request of data of event B, also start to execute Fig. 2 process.In the concrete realization, the process of Fig. 2 actually phase
When the method how done when some event of WEB page will be to server request data then defined, such as can be
This method, can be known as JSONL, and this method is placed on the library for calling by designer's good method prepared in advance
In;When event wants request data, then this method is called, and some parameters required for this method are transmitted to this method
In, the process that Fig. 2 is executed according to these parameters is completed the acquisition of data by this method.
For example, it is assumed that data resource is stored in the server, the storage address URL of the data resource are as follows: http: //
The resource content of www.alipay.com/info, address storage can be with are as follows:
define(
" name ": " Alipay "
“createDate”:“2004”
" description ": " Alipay network technology Co., Ltd "
“website”:“http://www.alipay.com”
“phone”:“0571-11110000”
)
And assumes that some event of WEB page will obtain the data, can be set in WEB page in webpage design personnel
The resource of meter such as under type access address above mentioned:
{ value is JSONL (" http://www.alipay.com/info ", " define ", function (value))
Content in resource }
I.e. designer can with by the above-mentioned means, call directly the method JSONL in library, and by parameter " http: //
Www.alipay.com/info ", " define ", function (value) are transferred to this method, are executed shown in Fig. 2 as this method
Request of data process.Wherein, " http://www.alipay.com/info " is the address of data storage, and " define " is
The function name for the executable script that server returns, and the first function in Fig. 3 also uses the function name;And function
It (value) is call back function, it is specified that how to use data resource.
In step 201, client can be generated request mark and respectively at the request identify corresponding request end and
Agent side, i.e. request end identify the request as the information for being used for the unique identification request end, and agent side also marks the request
Know as the information for being used for the unique identification agent side.
For example, a dynamic I D generator can be set in JSONL method, WEB page is being received to JSONL method
When calling, show to execute a data request event, then a random ID is created by dynamic I D generator, such as when difference
Between generate different random numbers as random ID, which requests mark.
Request to create end and agent side are also wanted in this step, for example creation one hiding empty IFRAME and one is entirely
Office's function will also establish the corresponding relationship of above-mentioned the request mark and the request end and agent side generated at random.For example, creation is asked
End second function window [function name]=function (value) is asked, the function name of the second function is exactly above-mentioned random
ID;An IFRAME is created,<iframe id=randomID></iframe>, i.e. the mark of the IFRAME is also request mark.
The client is by taking the WEB page of Fig. 3 as an example, when in the page including the event of multiple request of data, respectively often
Corresponding request mark is arranged in one request of data, for example, the corresponding request mark of event A is " 11 ", the corresponding request of event B
Mark is " 22 ".The second function of event A is window [11].
As described above, JSONL method is when creating second function, window [function name]=function (value),
The parameter function (value) of client transmissions is used, i.e. second function calls call back function to execute the processing to data.
And configured transmission " http://www.alipay.com/info " and " define ", it is the use in IFRAME creation,
In the creation of IFRAME, the above-mentioned request generated at random is set by the ID of IFRAME and is identified, and is dynamically created in IFRAME
SCRIPT label is built, URL incoming in advance is directed toward in address, initiates request of data to the URL.
For example, being created in IFRAME<script src=http://www.alipay.com/info></script>,
Which includes above-mentioned URL.In addition, also creating first function in iframe, function name is define.
After the foundation for completing above-mentioned iframe and respective function, in step 202, by what is generated in execution 201
Logic, agent side is to server request target data, such as perform script < scriptsrc=http: //
Www.alipay.com/info></script>, IFRAME just to server send request of data, request http: //
The target data of the address www.alipay.com/info.
In step 203, server returns to target data to agent side IFRAME, and the form of return is, for example, define
(target data), this is an executable script.The script is executed by the first function of IFRAME again and obtains target data, and
Target data is transmitted to the second function of request end.Second function calls call back function to handle the target data, i.e.,
Use target data performance objective business.
As described above, in WEB page include multiple request data event when, each event will call execution Fig. 2
Process, such as call JSONL method, parameter is transmitted to the JSONL, by this method according to be passed to parameter execute Fig. 2 institute
The process shown.When executing Fig. 2 process, each event can generate different request ID, and ID is as request end and generation for the request
Manage the mark at end.
It should be noted that request end and agent side are established by corresponding relationship by " request identifies " in the present embodiment, it can
To bring many effects, for example, shown in Figure 4, the event A and event B of WEB page all to server request data simultaneously,
The present embodiment does not limit whether request data is identical, but WEB page, when receiving the data of server return, it is accurate to need
Distinguishing the data returned is event A or event B.As shown in figure 4, being that event A is independent in the scheme of the present embodiment
Agent side IFRAME is created, the target data of request event A needs, and the request end of event A and the IFRAME are exclusively used in
Mark be all " 11 ";Agent side IFRAME is individually created for event B, is exclusively used in the target data of request event B needs, and
And the request end of event B and the mark of the IFRAME are all " 22 ", then can by the request identify establish request end and
The binding relationship of agent side, the data that IFRAME-22 is got can only be transmitted to request end --- and 22, without being transmitted to request
End -11, because mark is not identical.
It can be seen which event request is the data that this mode can accurately determine that server returns be, client can
Realize the data receiver of high accuracy.And for server, due to distinguishing the work of returned data and request end corresponding relationship
Make accurately to realize via client itself, server can use unified data to return to form, such as Fig. 4 example
, it is returned with the form of define (), that is, identical function name, in this way relative to the server side in traditional approach according to not
With request using different return function names (distinguishing the data of different requests according to different functions name in order to facilitate client) come
It says, server side saves resource consumption and development cost, accelerates response speed, and realize the static storage of data resource
Etc. many benefits.
In addition, can be same numeric field data for the target data of agent side request, being also possible to cross-domain data.It is requesting
It identifies corresponding request end and identifies corresponding agency using the request after target data performance objective business, can also be deleted
End.For example, the corresponding IFRAME -11 of event A can be deleted after event A has used target data.I.e. client is at certain
It when a event request data, is identified for the request of its dynamic generation, and creates the request and identify corresponding agent side IFRAME request
Data can delete the IFRAME after obtaining data, and request mark can also delete, and next time can generate again and distribute to it
His request of data.
In order to realize above-mentioned data request method, the embodiment of the present application also provides a kind of request of data device, the dresses
It sets and can be applied to client.As shown in figure 5, the apparatus may include: identifier generation module 51, function creation module 52;Its
In, identifier generation module 51, for generating request mark;Function creation module 52 is identified with the request respectively for creating
Corresponding request end 53 and agent side 54.
Agent side 54 for requesting target data required for the request end to server, and obtains the server
The target data of return;Request end 53 executes mesh using the target data for identifying corresponding request end by the request
Mark business.
Further, identifier generation module 51 are specifically used for generating the request at random by dynamic marks generating mode
Mark.
Further, function creation module 52, specifically for creating the overall situation function as request end, the overall situation function
Function entitled request mark, the overall situation function is used to use target data performance objective business;Creation is as agent side
Frame, the frame are hiding empty frames framves, and the request that is identified as that the frame is arranged identifies, and the frame is used for
By script tag to server request target data.
Further, the frame, specifically for executing the call back function that the server returns by internal overall situation function,
Obtain the target data that the server is returned by the call back function;And by the internal overall situation function by the target
Data are transmitted to the overall situation function as request end.
Further, request end 53 are also used to after using the target data performance objective business, ask described in deletion
Seek the corresponding agent side of mark.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all in essence of the invention
Within mind and principle, any modification, equivalent substitution, improvement and etc. done be should be included within the scope of the present invention.