3. scraping my self

| No Comments

While thinking about how do I pre-generate the "Email send, thank you." and "Email send error, please try again later." feedback AJAX responses I realized I don't. :-) I use the statically generated response pages and just web-scrape them.

The interresting part from feedback.js:

// setup feedback submit event
$('#feedback_form').submit(function() {
    $.post(
        $('#feedback_form').attr('action'),
        {
            name: $('#formName').attr('value'),
            email: $('#formEmail').attr('value'),
            subject: $('#formSubject').attr('value'),
            message: $('#formMessage').attr('value')
        },
        function (data) {
            $('#content_inside_main .error')
                .replaceWith($(data)
                .find('#content_inside_main .error'));
            $('#content_inside_main .info')
                .replaceWith($(data)
                .find('#content_inside_main .info'));
        }
    );

    $('#feedbackLink').click();
    
    return false;
});

First the submit of a form is hijacked and instead an AJAX post is issued. The CGI that is handling the POST is redirecting to either email-ok.html or email-fail.html. This pages are generated for non-JavaScript capable (disabled) browsers. After the AJAX call is successful function (data) {}; is called. The data variable is filled with the HTML. Then just content of #content_inside_main .error and #content_inside_main .info elements is replaced with the content of the same elements from data.

Fun huh? In this case yes, but in other the same technique is saving >300MB of content that will have to be pre-generated. But let's show that case some other time.

Leave a comment

Updates

Subscribe to the blog updates with an email:

If you like it, share it.

Pages

About this Entry

This page contains a single entry by Jozef Kutej published on November 6, 2009 7:55 PM.

2. a hook for you was the previous entry in this blog.

4. less can be more is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.