views:

33

answers:

1

Hello, my most trusted programmers and thank for all the help!

I grab rss-feed by jquery-ajax using php curl. It's loading very nicely directly on the page. However, I would like to translate the text, that is now html, title within h2 and text within p, wrapped by a div-container.

Google's api-script for translation doesn't seem to run after the content was put into the div. Really nothing happens. I tried both putting the script in the ajax-url-file and the file that the content is displayed on.

I used .live(), but no result.

Any idea?

Thanks!

--

In one of the methods I create a table i mysql and put in title, link and text. After that I echo the table.

$query3 = mysql_query("SELECT * FROM temp_rss_$id") or die("$error_msg");
while ($row3 = mysql_fetch_array($query3)) {
    $title = htmlentities($row3['title']);
    $text = htmlentities($row3['text']);
    $link = $row3['link'];
echo "

        $titel

        $text
";
}

The title is within in a h2 and an anchor, and the text is within a p.

Using simple jquery, this method without ajax, to grab this:

$('a.rss-links').live('click', function() {
    $('#media').load(php_file);
});

Works like a charm. Then there's the google-api-script:

function initialize() {
    var text = document.getElementById('media').innerHTML;
    google.language.detect(text, function(result) {
        if (!result.error && result.language) {
            google.language.translate(text, result.language, "en", function(result) {
                var translated = document.getElementById("media");
                if (result.translation) {
                    translated.innerHTML = result.translation;
                }
            });
        }
    });
}
google.setOnLoadCallback(initialize);

It doesn't load the google-script. What can be done? Of course it does work if I put the text directly on the page, without loading another file. Using ajax and append(result) instead of .load doesn't make a difference. Any idea?

Thanks!

A: 

You can call that function after the .load() runs, as it's callback, like this:

$('a.rss-links').live('click', function() {
    $('#media').load(php_file, initialize);
});

This will call the initialize function once the .load() has completed and the new content in the #media element is there and ready to translate.

Nick Craver