Link to home
Start Free TrialLog in
Avatar of jxbma
jxbmaFlag for United States of America

asked on

How do I intercept all page postbacks in jquery before they occur?

Hi:

I've got of client side processing on a web page which needs to be completed before the page posts back to the server.
There are several operations on the page which could result in a postback, so I would like to universally intercept the postback on the client side before it occurs, complete some processing and proceed with the postback.

What is the best way to do this in jquery?

Thanks,
JohnB
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hans Langer
Hans Langer

if you are using $.ajax({..}) you can set the properties off all the calls that you will use with "$.ajax" function.

I.E.:
$.ajax({beforeSend:function(jqXHR,settings){
//DO SOMETHING BEFORE SEND THE DATA TO THE SERVER
}})

Open in new window

if its only a page that have forms then you can just set the "submit" event of the forms.
$('form').submit(function(){
//your process
//return false to cancel the submit
//return true to proceed with the submit
})

Open in new window

Avatar of jxbma

ASKER

Ultimately, this was the solution I chose to go with.

Thx