1

I want to load the controller of codeigniter in ajax url.

This is the code in the head of the main view of codeigniter:

<script type="text/javascript">

        var x = 1;

        function cek(){
            $.ajax({
                url: "<?=base_url();?>cekPesan",
                cache: false,
                success: function(msg){
                    $("#notifikasi").html(msg);
                }
            });
            var waktu = setTimeout("cek()",3000);
        }

        $(document).ready(function(){
            cek();
            $("#pesan").click(function(){
                $("#loading").show();
                if(x=1){
                    $("#pesan").css("background-color","#efefef");
                    x = 0;
                }else{
                    $("#pesan").css("background-color","#4B59a9");
                    x = 1;
                }
                $("#info").toggle();
                //ajax untuk menampilkan pesan yang belum terbaca
                $.ajax({
                    url: "<?=base_url();?>lihatPesan",
                    cache: false,
                    success: function(msg){
                        $("#loading").hide();
                        $("#konten-info").html(msg);
                    }
                });

            });
            $("#content").click(function(){
                $("#info").hide();
                $("#pesan").css("background-color","#4B59a9");
                x = 1;
            });
        });

    </script>

When I run it, the page can not be loaded. I don't understand why.

7
  • Have you loaded the URL helper? Do you have firebug available? It really helps with ajax. Commented Jul 16, 2012 at 16:06
  • sure,, i have load the url helper... Commented Jul 16, 2012 at 16:09
  • Any errors, messages, etc. in your console? Commented Jul 16, 2012 at 16:43
  • 1
    Thank you for Dale and Collin,, after try in firebug like dale ask for me,, now,, i find the error is bad request,, So,, i just add type: "REQ" --> For the request now, it works well... Commented Jul 16, 2012 at 17:06
  • 3
    Please don't add (SOLVED) or anything like that to the topic, rather post the solution as an answer yourself and accept it as the correct answer. Commented Jul 16, 2012 at 17:15

1 Answer 1

-1

check, are you loaded URL helper. and in your application php short tags is allowed or not.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.