Ajax not loading part of the page

May 7, 2014 in answer

0 votes, 0.00 avg. rating (0% score)

ANSWER:

Your code can be simplified like this:

$(document).ready(function()
    $("#doc1").click(function()
        $("#mensagem").load(
            'http://localhost/ajax/ajax/ajax_titulo_texto.php?id=1');
    );
});

Better yet, you can specify the id on the #doc1 and use it in the click handler like this:

HTML

Click me

JavaScript

$(document).ready(function()
    $("#doc1").click(function()
        $("#mensagem").load(
            'http://localhost/ajax/ajax/ajax_titulo_texto.php?id='+ 
                $(this).attr('target-id'));
    );
});

Even better, you should have one click handler to do all the work, rather than repeating the code per #id. Check this out:

HTML

Click me #1
Click me #2
Click me #3

JavaScript

$(document).ready(function()
    $(".docMenu").click(function()
        $("#mensagem").load(
            'http://localhost/ajax/ajax/ajax_titulo_texto.php?id='+ 
                $(this).attr('target-id'));
    );
});

Latheesan Kanes from http://stackoverflow.com/questions/23512244