1

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

 }
7
  • can you write my url in proper way so that i can copy it into my code Commented Mar 17, 2018 at 14:23
  • its not working i tried Commented Mar 17, 2018 at 14:25
  • it should be like this ` url: "localhost/CodeIgnitorTutorial/index.php/usercontroller/…",` Commented Mar 17, 2018 at 14:27
  • Check in network tab which url it is taking. Commented Mar 17, 2018 at 14:31
  • seems like you missed name of page in url , it should be like url: "<?php echo base_url(); ?>" + "page.php/ajax_post_controller/user_data_submit" Commented Mar 17, 2018 at 14:39

2 Answers 2

2

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 :-

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

Comments

1

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

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.