Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

With standard AJAX, I can cancel a request-in-progress by using xhr.abort():

var xhr = new XMLHttpRequest();
// set up my xhr
// etc...
xhr.send();

// Later: realize I don't want the response after all...
xhr.abort();

Is there any way to do this with actionFunctions?

My use case is a complex search interface where the request-response-rerender circuit can take several seconds. We've decided not to disable the search interface during the query, so it's possible for a user to realize they want to refine their criteria and requery. So in the query function, I want to check whether there's already a request in process, cancel it if there is, and send a new one. Here's the simplified concept:

<apex:actionFunction name="doSearch" value="{!doSearch}">
    <apex:param name="myParams" assignTo="{!queryParams}" value=""/>
</apex:actionFunction>

<script>
function prepareQuery() {
     // grab values from the search form, client-side validation, etc.
     // if we're going to query:
     someWayToCancelPreviousQuery();
     doSearch(myParams);
}
</script>

Thanks!

share|improve this question
    
If I had to guess, apex:actionFunction doesn't automatically execute XMLHttpRequest functions. Most action calls perform an HTTP post, unless they are using the reRender action, which hooks into the AJAX partial page refresh functionality of the VF page. I've not actually cracked this open to understand, this is just what I suspect based on observation. And if that's the case, you'll have nothing to abort. –  Peter Jan 22 '13 at 16:14
    
Interesting. I guess the question would be, "can I interrupt VF to prevent the rerendering." Will take more digging at some point... –  Benj Jan 22 '13 at 18:50

1 Answer 1

I would try with timeout param of actionFunction:

<apex:actionFunction timeout="500" />

After 30 secs the actionFunction will be cancelled (timeouted) automatically.

The amount of time (in milliseconds) before an AJAX update request should time out.

Docs

share|improve this answer
    
Thanks @Mastor, but I'm not trying to cancel automatically. If the conditions merit cancelling, I want to cancel even w/in a specified timeframe. And if I'm not cancelling, the whole request may need a couple seconds to succeed. –  Benj Jan 21 '13 at 16:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.