开发者

jQTouch AJAX Form Callback

开发者 https://www.devze.com 2023-03-15 04:55 出处:网络
I\'ve got a simple AJAX POST form set up in a jQTouch application. We\'re talking out-of-the-box simple here:

I've got a simple AJAX POST form set up in a jQTouch application. We're talking out-of-the-box simple here:

<form id="contact" class="topPage" method="post" action="/process/mobile-submit.cfm">
   <!-- Various form guts go here -->
</form>

And this works just great. My users punch in their info, my server-side script does its job and gobbles up the lead data and spits back an out-of-the-box simple response.

<div>
    <div class="toolbar">
        <a href="#contact" class="slide back">Back</a>
    </div>
    <div class="info">
        <strong>Thank You For Your Submission</strong><br />
        We have received your inquiry, and blah blah blah jibber jabber.
    </div>
</div>

Everyone's happy... except those of us who are trying to track the conversion in Google Analytics. Now, I've got virtual pageviews set up on each panel in this application using the pageAnimationEnd event, which is easy as pie when you know what selectors those are going to be attached to in advance, but when jQTouch creates a new segment from the form return, it has a generic serialized ID like #page-N.

I've tried adding a loose script block into the form return. Tha开发者_开发技巧t works fine for Firefox on my desktop, not so much for Safari on my phone.

Since I've allowed jQTouch to handle the AJAX particulars for me in this instance, is there a straightforward way to attach a success handler to it? Or am I better off trying to bind a pageAnimationEnd handler on $('[id^=page-]') and hope the business doesn't want me to do anything else with ad hoc form returns until we replace this app with one written in jQuery Mobile?


Worked it out. The return fragment can declare its own ID, naturally, and jQTouch will then treat it as though it were an original part of the document. I had previously assumed jQTouch didn't give a toss about what attributes I gave the fragment; I was wrong.

This means that you could goTo it like any other portion of the document. It also means that you can bind a pageAnimationEnd handler on the return fragment either by ID or by class name and it will behave as expected. Thus:

<div class="formResult">
<div class="toolbar">
    <a href="#contact" class="slide back">Back</a>
</div>
<div class="info">
    <strong>Thank You For Your Submission</strong><br />
    We have received your inquiry, and blah blah blah jibber jabber.
</div>

And:

$('.formReturn').live('pageAnimationEnd', function(evt, info) {
    if (info.direction == 'in') {
        // Goal completion code
    } else {
        $(this).remove();
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号