shani
shani

Reputation: 11

how to write url in ajax request in codeigniter php?

i'm new to codeigniter i can't not get data from the controller using the ajax request i think i do mistake in writing the url of the controller function in ajax call

here is the code of my ajax call

$(document).ready(function(){
    $("#fname").focusout(function(){
       // alert();
              $.ajax({
                  url: "<?php echo base_url();?>/proposal/ajax_load",
                  type: 'POST',
                  success: function(result){
                        $("#div1").html(result);
                    }
        });  
    });
});

Here is my controller

class Proposal extends CI_Controller {
 public function ajax_load()
  {
        return ("Hello");
    }

 }

Upvotes: 1

Views: 166

Answers (2)

Karlo Kokkak
Karlo Kokkak

Reputation: 3714

in ajax_load() - Should be echo not return if you're getting a response via ajax.

Upvotes: 1

hassan
hassan

Reputation: 8288

You are confuse between the meaning of [Return, Echo] in PHP,

Echo

echo — Output one or more strings

Return

return returns program control to the calling module. Execution resumes at the expression following the called module's invocation.

and as long as the Ajax response callback is reading a server response [output], you must send an output to the server.

public function ajax_load()
{
    echo "Hello";
}

Further reading :-

Upvotes: 2

Related Questions