2009-11-06T19:55:33+01:00

3. scraping my self

hand-with-scrapes.jpg

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.