user1410644
user1410644

Reputation: 351

jquery load doesn't show particular href

I'm trying to update a page with jQuery load function when a user add a row in the DB.

Here is my code:

PHP file:

$blogs = getBlogsFromDB();
foreach ($blogs as $blog) {
    if (strlen($blog["title"]) > 23) {
        $blog["title"] = substr($blog["title"], 0, 20) . '...';
    }

    echo '<div class="image-box">
            <span class="drag-pointer">&nbsp;</span>
            <!-- Blog picture -->
            <div class="blog-picture">
                <a href="' . $blog["url"] . '" target="_blank"><img src="' . $blog["avatar"] . '" alt="" /></a>
            </div>
            <!-- end blog picture -->

            <!-- blog name -->
            <p class="blog-name"><a href="' . getBlogUsername($blog["url"]) . '" target="_blank" />' . $blog["title"] . '</a></p>
            <!-- end blog name -->

        </div>';
}

And here is the jQuery part:

$.ajax({
    type: "POST",
    url: "add_blog.php",
    data: dataString,
    dataType: 'json',
    success: function(response) {
        if (response.status == "1")
        {
            $('#add-blog').html("<div id='message'></div>");
            $('#message').html("<h2>Success! Your blog is added!</h2>")
            .hide()
            .fadeIn(500, function() {
                $('#message').append("<img id='checkmark' src='js/images/check.png' />");
            });
            $('#blogs').load('blogs.php');
        }
    }
});

After I add a row in the DB, blogs.php is loaded on the page but it doesn't show these links:

                <!-- blog name -->
                <p class="blog-name"><a href="' . getBlogUsername($blog["url"]) . '" target="_blank" />' . $blog["title"] . '</a></p>
                <!-- end blog name -->

I'm sure the problem is not in the PHP function because I've tried with hardcoded URL. It shows just the title($blog["title"]).

PS: I've tried to debug it with Firebug but everything seems to be okay there.

Any help will be appreciated!

Upvotes: 0

Views: 165

Answers (1)

jeroen
jeroen

Reputation: 91734

Without seeing the generated html, I would say that the problem is the self-closing a tag:

<a href="' . getBlogUsername($blog["url"]) . '" target="_blank" />
                                                                ^ here

Just change it to:

<a href="' . getBlogUsername($blog["url"]) . '" target="_blank">

Upvotes: 1

Related Questions