Summary of the invention
Technical problem to be solved by this invention provides a kind of method that prevents duplicate button pressing by user, in Web uses, needs the extra loaded down with trivial details and cost problem of higher of work that code brings of writing in order to solve.
Another object of the present invention is that above-mentioned design is applied in the concrete applied environment, and a kind of device that prevents duplicate button pressing by user is provided, thereby guarantees the realization and the application of this method.
For solving the problems of the technologies described above, the embodiment of the invention provides a kind of method that prevents duplicate button pressing by user, comprising:
Whether the operation of judges button click is an effective click event, if then the state of button is set to forbidding, and sends the processing request of said click event to server;
When receiving the result of server, the state of button is set to available.
Preferably, saidly send the processing request of said click event, specifically comprise to server:
Receive the trigger request of the event handling unit transmission of button, said trigger request is used to trigger asynchronous JavaScript and extend markup language AJAX assembly is started working;
The AJAX assembly sends the processing request of said click event to server.
Preferably, said AJAX assembly sends before the processing request of said click event to server, also comprises:
Receive the call back function of the event handling unit transmission of button,
Then the state of said button is set to availablely, specifically comprises:
According to said result, carry out said call back function;
According to the correlative code in the said call back function, be updated to the state of button available.
Preferably, saidly send the processing request of said click event, specifically comprise to server:
Send AJAX request to server based on extend markup language HTTP XMLHTTP.
Preferably, the content of said processing request comprises: the target location of server and the required parameter relevant with said click event.
The embodiment of the invention also provides a kind of device that prevents duplicate button pressing by user, comprising:
Judge module, whether the operation that is used for the judges button click is an effective click event;
First is provided with module, be used for when the result of said judge module when being, the state of button is set to forbidding;
Send and handle request module, be used for sending the processing request of said click event to server;
Second is provided with module, is used for when receiving the result that server returns, and the state of button is set to available.
Preferably, said transmission processing request module specifically comprises:
First receives submodule, is used to receive the trigger request that the event handling unit of button sends, and said trigger request is used to trigger asynchronous JavaScript and extend markup language AJAX assembly is started working;
Send submodule, be used for sending the processing request of said click event to server.
Preferably, said sending module comprises that also second receives submodule, is used to receive the call back function that the event handling unit of button sends,
Then said second is provided with module specifically comprises:
Implementation sub-module is used for carrying out said call back function according to said result;
Updating submodule is used for the code according to said call back function, is updated to the state of button available.
Preferably, said processing request is specially: based on the AJAX request of extend markup language HTTP XMLHTTP.
Preferably, the content of said processing request comprises: the target location of server and the required parameter relevant with said click event.
Compared with prior art, the present invention has the following advantages:
Step of the present invention comprises: at first whether the operation of judges button click is an effective click event; If; " forbidding " method of call buttons object then, the state of button are set to forbidding, and send the processing request of said click event to server; When receiving the result of server, the state of button is set to available more then.Use method of the present invention, whether the user does not need extra writing to prevent the code of the continuous button click of user, effective through the clicking operation of judges; Can be untreated in the incident of one click button when complete; Make the user can not continue to click this button through the disabled status that button is set, and after a newsletter was handled, the state of button was set to available again; Thereby in Web uses; Need not to write the purpose that code can realize preventing duplicate button pressing by user, thereby reduced the work fussy degree of writing code, and reduced development cost.
Embodiment
For make above-mentioned purpose of the present invention, feature and advantage can be more obviously understandable, below in conjunction with accompanying drawing and embodiment the present invention done further detailed explanation.
The present invention can be used in numerous general or special purpose calculation element environment or the configuration.For example: personal computer, server computer, handheld device or portable set, plate equipment, multiprocessor device, comprise DCE of above any device or equipment or the like.
The present invention can describe in the general context of the computer executable instructions of being carried out by computer, for example program module.Usually, program module comprises the routine carrying out particular task or realize particular abstract, program, object, assembly, data structure or the like.Also can in DCE, put into practice the present invention, in these DCEs, by through communication network connected teleprocessing equipment execute the task.In DCE, program module can be arranged in this locality and the remote computer storage medium that comprises memory device.
With reference to figure 1, show a kind of flow chart that prevents the method embodiment 1 of duplicate button pressing by user of the present invention, can may further comprise the steps:
Step 101: whether the operation of judges button click is an effective click event;
Step 102: when user's clicking operation was an effective click event, the state of button was set to forbidding;
Step 103: the processing request of sending said click event to server;
Step 104: when receiving the result that server returns, the state of button is set to available.
In the present embodiment, whether the operation through the judges button click is an effective click event, if the state of the button mode that is set to forbid then; Carrying out the Business Processing of this click event, promptly is to click button No. one time as the user, carries out in the processing procedure of this incident; This button can not effectively be clicked use by the user once more; When receiving the result of the said click event that server returns, the state of button is set to available then, and the request of representing this click event is processes complete; At this moment, the function of this button can normally continue to use.
Need to prove; The button of mentioning in the present embodiment has carried out the control of some scripts in client to it, and the control of said script is included among the code of button itself; The button that the user can provide present embodiment; Be used as a common button and use and get final product, need not extraly to write code for it, and the use that can in a plurality of systems, repeat; Can find out that owing to the present invention is to provide an a kind of button assembly that has encapsulated complete function, this button assembly can directly be added in the system and use; Therefore, through method of the present invention, the user does not need extra writing to prevent the code of the continuous button click of user; Can be untreated in the incident of one click button when complete, make the user can not continue to click this button, thereby in Web uses; Reduce the work fussy degree of writing code, and reduced development cost.
Before introducing the embodiment of the invention 2, at first introduce the notion of call back function.Call back function is a kind of encapsulation technology of assembly; Call back function requires statement by user program according to assembly usually; And when calling initiation, pass to assembly, when assembly in invoked process certain incident takes place, can call this call back function and give the user program processing disposal right.Between most high-level language, take place mutual in, can adopt the mechanism of call back function.
With reference to figure 2, show a kind of flow chart that prevents the method embodiment 2 of duplicate button pressing by user of the present invention, present embodiment can may further comprise the steps:
Step 201: whether the operation of judges button click is an effective click event;
In the present embodiment; The state of said button has two kinds of forbiddings and available, and when button state was forbidding, the operation of user's button click just was not once effective click event; When the state of button when being available, user's clicking operation could become the one click incident effectively; Therefore, the purpose that this step is judged the operation of user's button click promptly is in order to obtain the button current states;
Step 202: when user's clicking operation was effective, the state of button was set to forbidding;
In present embodiment 1, can be through the Javascript that adopts browser to provide, " forbidding " method of call buttons object, button is set to " forbidding " state;
Step 203:AJAX assembly receives the trigger request and the call back function of the event handling unit transmission of button, and said trigger request is used to trigger asynchronous JavaScript and extend markup language AJAX assembly is started working;
The state of button is set to after the forbidding, and the event handling unit sends trigger request and predefined call back function to the AJAX assembly, and said trigger request is used to trigger the AJAX assembly and starts working; Comprise the code that button is updated to upstate in the said call back function, be used for when receiving the return results of server, carrying out;
Step 204:AJAX assembly sends the processing request of said click event to server;
In the present embodiment; The AJAX assembly sends an AJAX request based on extend markup language HTTP XMLHTTP to server, and the content of said AJAX request specifically can comprise: the target location of server and the required parameter relevant with said click event; For example; Can the content of AJAX request specifically be http://localhost:8080/myapp/action? A=b; Wherein: http://localhost:8080/myapp/action is called uniform resource position mark URL; A=b refers to required parameter, and the user can send arbitrarily parameter according to the current page to server;
The result that step 205:AJAX assembly reception server returns;
Server carries out a series of response process after receiving said Business Processing request, and result is back to the AJAX assembly; For the present invention, what processing server does does not influence realization of the present invention, and what the result no matter server returns is, can trigger the execution of call back function;
Step 206:AJAX assembly is carried out said call back function according to said result;
The AJAX assembly according to the result that receives, is carried out said call back function again;
Step 207:, be updated to the state of button available according to the correlative code in the said call back function.
When call back function is carried out, can be according to the code of the renewing button state that comprises in the call back function, be updated to the state of button available.
Embodiment 2 is for embodiment 1; More detailed, preferred embodiment; Newsletter process between the concrete client and server and button state are set to available process have carried out detailed description, other parts can be referring to the associated description of embodiment 1.
Need to prove; For aforesaid each method embodiment, for simple description, so it all is expressed as a series of combination of actions; But those skilled in the art should know; The present invention does not receive the restriction of described sequence of movement, because according to the present invention, some step can adopt other orders or carry out simultaneously.Secondly, those skilled in the art also should know, the embodiment described in the specification all belongs to preferred embodiment, and related action and module might not be that the present invention is necessary.
With reference to figure 3, show a kind of structured flowchart that prevents the device embodiment 1 of duplicate button pressing by user of the present invention, can comprise with lower module:
Judge module 301, whether the operation that is used for the judges button click is an effective click event;
First is provided with module 302, be used for when the result of said judge module when being, the state of button is set to forbidding;
Send and handle request module 303, be used for sending the processing request of said click event to server;
Second is provided with module 304, is used for when receiving the result that server returns, and the state of button is set to available.
In the present embodiment; Said device can comprise four modules; Said judge module can the judges button click operation whether be an effective click event, when the result of said judge module for being, said first be provided with module in the result of said judge module when being; State that can button is set to forbidding; The processing request that request module can be sent said click event to server is handled in simultaneously said transmission, and said second is provided with module can be when receiving the result that server returns, and is set to the state of button available again; Can find out, in the present embodiment, through after user's button click; Button state is set to forbidding, and after the event handling of this time button click finished, the state of button was set to available again; Can prevent duplicate button pressing by user; The user need not to write extra code, thereby has reduced the fussy degree of work, has reduced development cost.
With reference to figure 4, show a kind of structured flowchart that prevents the device embodiment 2 of duplicate button pressing by user of the present invention, can comprise with lower module:
Judge module 401, whether the operation that is used for the judges button click is an effective click event;
First is provided with module 402, be used for when the result of said judge module when being, the state of button is set to forbidding;
First receives submodule 403, is used to receive the trigger request that the event handling unit of button sends, and said trigger request is used to trigger asynchronous JavaScript and extend markup language AJAX assembly is started working;
Send submodule 404, be used for sending the processing request of said click event to server;
In the present embodiment; Said processing request can be an AJAX request based on extend markup language HTTP XMLHTTP, and the content of said processing request specifically can comprise: the target location of server and the required parameter relevant with said click event;
Second receives submodule 405, is used to receive the call back function that the event handling unit of button sends;
Implementation sub-module 406 is used for carrying out said call back function according to said result;
Updating submodule 407 is used for the code according to said call back function, is updated to the state of button available.
Need to prove that each embodiment in this specification all adopts the mode of going forward one by one to describe, what each embodiment stressed all is and the difference of other embodiment that identical similar part is mutually referring to getting final product between each embodiment.For device type embodiment, because it is similar basically with method embodiment, so description is fairly simple, relevant part gets final product referring to the part explanation of method embodiment.
Need to prove; In this article; Relational terms such as first and second grades only is used for an entity or operation are made a distinction with another entity or operation, and not necessarily requires or hint relation or the order that has any this reality between these entities or the operation.And; Term " comprises ", " comprising " or its any other variant are intended to contain comprising of nonexcludability; Thereby make and comprise that process, method, article or the equipment of a series of key elements not only comprise those key elements; But also comprise other key elements of clearly not listing, or also be included as this process, method, article or equipment intrinsic key element.Under the situation that do not having much more more restrictions, the key element that limits by statement " comprising ... ", and be not precluded within process, method, article or the equipment that comprises said key element and also have other identical element.
More than a kind ofly prevent the method for duplicate button pressing by user and prevent that the device of duplicate button pressing by user from having carried out detailed introduction provided by the present invention; Used concrete example among this paper principle of the present invention and execution mode are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, the part that on embodiment and range of application, all can change, in sum, this description should not be construed as limitation of the present invention.