Welcome Guest, Not a member yet? Register   Sign In
jquery problam
#1

[eluser]A.M.F[/eluser]
i have articles' list that i echo in one page.
after the list i have a block and inside the block i want to load each article with jQuery so i have this JS script:
Code:
$(document).ready(function() {
                          
    $("#msg_list a[@class='msg']").click(function(){
              $.post("<?=site_url_rel("profile/pm/6")?>", {msg_list: $(this).html()}, function(xml) {
            $("#the_msg").html(
                $("test", xml).text()
            );
        });
                            
        return false;
    });

});

this is my HTML:
Code:
<div id="the_msg" style="float: left; border:1px #000 solid; display:block; width:60%; margin:5px; padding:5px;">
*** ARTICLE's CONTENT BLOCK ****
</div>
&lt;!-- articles' list --&gt;
<div id="msg_list">
    <a href="#" class="msg">test</a>
</div>

and finally, that's my pm function in the controller:

Code:
function pm($pm_id = '')
{
        // -- check data: --
    $pm_id = $this->uri->segment(3, TRUE);
    if ((!is_numeric($pm_id)) || ($pm_id == '')) show_error('ההודעה לא נמצאה');
    $pm_id = htmlspecialchars($pm_id, ENT_QUOTES);

    // --- get message ---&gt;
    $query = $this->db->query("SELECT * FROM `messages` WHERE `msg_id`='{$pm_id}'");
    if ($query->num_rows == 0) show_error('ההודעה לא נמצאה');
    $row = $query->row();
        
    $title     = $row->msg_title;
    $content = $row->msg_content;
    // ----------------&gt;

    $xml = "<msg_list><test>12</test></msg_list>";
    header('Content-type: text/xml');
    echo $xml;
}


the result is this: when i click on the link - nothing happens.
why?

thank u for ur time
#2

[eluser]coldKingdom[/eluser]
Test this:

Code:
$(document).ready(function() {
                          
    $(".msg").click(function(){
              $.post("&lt;?=site_url_rel("profile/pm/6")?&gt;", {msg_list: $(this).html()}, function(xml) {
            $("#the_msg").html(
                $("test", xml).text()
            );
        });
                            
        return false;
    });

});
#3

[eluser]A.M.F[/eluser]
not working... i just want to load data into a page with AJAX. why does it makes me such a head-ache? :/
#4

[eluser]xwero[/eluser]
Try it with html output
Code:
// controller
function pm($pm_id = '')
{
        // -- check data: --
    $pm_id = $this->uri->segment(3, TRUE);
    if ((!is_numeric($pm_id)) || ($pm_id == '')) show_error('ההודעה לא נמצאה');
    $pm_id = htmlspecialchars($pm_id, ENT_QUOTES);

    // --- get message ---&gt;
    $query = $this->db->query("SELECT * FROM `messages` WHERE `msg_id`='{$pm_id}'");
    if ($query->num_rows == 0) show_error('ההודעה לא נמצאה');
    $row = $query->row();
        
    $title     = $row->msg_title;
    $content = $row->msg_content;
    // ----------------&gt;

    $xml = "<msg_list><test>12</test></msg_list>";
    //header('Content-type: text/xml');
    echo $xml;
}
// javascript
$(document).ready(function() {
                          
    $("#msg_list a[@class='msg']").click(function(){
              $.post("&lt;?=site_url_rel("profile/pm/6")?&gt;", {msg_list: $(this).html()}, function(xml) {
            $("#the_msg").html(xml);
        });
                            
        return false;
    });

});
Do you get a result?
#5

[eluser]A.M.F[/eluser]
xwero - may the force be with you! - it worked!!

buuuttt (and there is always a but huh?)-
i have an encoding problam, and instead of printing what i want (the letters in my language), it prints "??????" (question marks) - altough the files are saved in the same encode foramt and in the HTML there is an encoding meta and in my DB it's also fine.

why is that?
#6

[eluser]xwero[/eluser]
try to add the header
Code:
header('Content-Type: text/html; charset=windows-1252');
With the charset that shows your language.
#7

[eluser]A.M.F[/eluser]
[quote author="xwero" date="1204222256"]try to add the header
Code:
header('Content-Type: text/html; charset=windows-1252');
With the charset that shows your language.[/quote]

just as easy as that. Smile
many thanks, i appreciate that
#8

[eluser]Rascal2pt0[/eluser]
have you tried using firebug(with firefox)? I've found firebug is very helpfull when trying to debug these wonderfully formatted jQuery problems.




Theme © iAndrew 2016 - Forum software by © MyBB