CodeIgniter Forums
jquery problam - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: jquery problam (/showthread.php?tid=6442)



jquery problam - El Forum - 02-27-2008

[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


jquery problam - El Forum - 02-27-2008

[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;
    });

});



jquery problam - El Forum - 02-28-2008

[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? :/


jquery problam - El Forum - 02-28-2008

[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?


jquery problam - El Forum - 02-28-2008

[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?


jquery problam - El Forum - 02-28-2008

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


jquery problam - El Forum - 02-28-2008

[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


jquery problam - El Forum - 02-29-2008

[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.