5

when i try to make AJAX request with jQuery as a response i get the html of the same page ! here is a live preview (edit not available due to me fixing it )

here are my files Edit : I have made changes to some of the files

main controller :

Class Main extends Controller {

function Main() 
{
      parent::Controller();   
}

function index(){

    $this->load->view('oxila_index');
}}

Oxila_index view ( just the JS rest of the html is in the link above )

 <script type="text/javascript">
        $(document).ready(function(){
            $("#inv").hide();
        });
        $(document).ready(function(){
            $("#submit").click(function(evt){

                $.post("/ajax/process", {
                    url: $("#url").val()
                }, function(response){
                        $("#output").html("");
                    $("#inv").show("slow"); 
                        $("#output").html(response);
                }, "text");
                evt.preventDefault();
            }); 
        });
    </script>

Ajax Controller

Class Ajax extends Controller {

    function process(){

        $data['url'] = $this->input->post('url');
        $this->load->view('test',$data);
        echo "hello world";
    }
}
4
  • could you add more code? The output doesn't make sense. echo $this->input->post('lurl'); You have a $this->load->view() somewhere... Commented Feb 1, 2010 at 2:31
  • so, what does the view, test.php contain? Commented Feb 1, 2010 at 9:30
  • whoops , forgot that , but it contains simple <?php echo $url; ?> Commented Feb 1, 2010 at 15:12
  • Hey man, I'm with the same problem (but I'm not using codeIgniter), how did you fixed it? Commented Feb 8, 2012 at 12:12

5 Answers 5

1

I just tried your page, and it work well. FYI, I use google chrome in Linux.

I have a few notes though. First, move the script from <head> to the bottom of the page, above </body>. This is best practice, since loading js code will block concurrent loading of other page element, css and images.

Second, if you not change anything in the server side, use GET instead of POST. To avoid caching in IE, just add another parameter that have random value.

Third, the line $("#output").html(""); is not necessary. You can put the $("#output").html(response); because .html() will replace any existing content inside the container. No need to emptied it.

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

1 Comment

yes i fixed it last night ill add the solution in a bit , and thanks for the tips :)
1

This is what a person in the forums told me

you definitely have something in place. Every single path I type in after the url leads me to the home page.

Try changing your URL Protocol from AUTO to something else. (this can be found in the config/config.php file)

i changed it to “REQUEST_URI” and it works !

Comments

0

You dont have a view for Your Test Function and Your Model to handle the Post Request isnt present

Comments

0

make sure your config has this setting to FALSE;

$config['compress_output'] = FALSE;

Comments

0

Why public function?

public function test(){

    echo $this->input->post('lurl');

    }

Remove public and just make it a function as anyone else: http://codeigniter.com/user_guide/general/controllers.html

Try also to include the whole URL in the javascript to try if it work:

$.post("http://yourwebsite/oxila/test/")

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.