vikrantmohite Posted November 21, 2011 Share Posted November 21, 2011 Please help me in this guys....... I am using MVC model for my application . I am stuck with the ajax call. this is my controller application/controller/admin/index.php function getCity() { $city=$this->model->getCity(); foreach($this->city as $key => $value) { echo '<option>'.$value['name'].'</option>' ; } } this is my model application/model/admin_model.php public function getCity() { if($_POST['id']) { $cid=$_POST['id']; $sth = $this->db->prepare('SELECT id, name FROM unit WHERE cid= :cid'); $sth->execute(array(':cid' => $cid)); return $sth->fetchAll(); } } this is my view <form id="city" action="<../application/admin/regstr/" method="post"> Country <select name="country" class="country"> <option value="" selected="selected">--Select Taluka--</option> <option value="1">India</option> <option value="2">USA</option> <option value="3">China</option> </select> City <select name="city" class="city"> <option selected="selected">--Select City--</option> </select> <input type="submit" /> </form> and this is my javascript for Ajax $(document).ready(function() { $(".country").change(function() { var id=$(this).val(); var dataString = 'id='+ id; $.ajax ({ type: "POST", url: "admin/getCity", data: dataString, cache: false, success: function(html) { $(".city").html(html); } }); }); }); But I am not getting the output. I have tested it with firebug in response tab. Instead of getting only option values html code as output I am getting the whole HTML page content (i.e. content of view page admin/index.php. Please help me out. Quote Link to comment https://forums.phpfreaks.com/topic/251537-help-in-ajax-call/ Share on other sites More sharing options...
Alexv Posted November 21, 2011 Share Posted November 21, 2011 The path for that controler function is admin/index/getCity. Change your javascript. Quote Link to comment https://forums.phpfreaks.com/topic/251537-help-in-ajax-call/#findComment-1289948 Share on other sites More sharing options...
vikrantmohite Posted November 21, 2011 Author Share Posted November 21, 2011 The path for that controler function is admin/index/getCity. Change your javascript. Thanx for quick reply. I am using MVC So I have to call a function in controller which inturn receive data from model. admin is controller class and getCity is its method. getCity method calls model and receives data from it. So I dont think admin/index/getCity is going to work for me. mu Url is like localhost/application/controller/{method}/{arg if any} structure Quote Link to comment https://forums.phpfreaks.com/topic/251537-help-in-ajax-call/#findComment-1289958 Share on other sites More sharing options...
Alexv Posted November 21, 2011 Share Posted November 21, 2011 Are you using any framework or did you build app from scratch? It looks to me like CodeIgniter thats why i said to fix the link in JS. What is the name of class inside of admin/index.php controler? Quote Link to comment https://forums.phpfreaks.com/topic/251537-help-in-ajax-call/#findComment-1290098 Share on other sites More sharing options...
vikrantmohite Posted November 21, 2011 Author Share Posted November 21, 2011 Are you using any framework or did you build app from scratch? It looks to me like CodeIgniter thats why i said to fix the link in JS. What is the name of class inside of admin/index.php controler? I am building application from scratch in MVC framework. I am not using CodeIgniter. I am using controller admin.php. ..//application/controllers/admin.php Quote Link to comment https://forums.phpfreaks.com/topic/251537-help-in-ajax-call/#findComment-1290101 Share on other sites More sharing options...
vikrantmohite Posted November 21, 2011 Author Share Posted November 21, 2011 My function get called But I am not getting response properly. Rather than getting only requested output I am getting whole HTML page as output in response. I have tested it in firebug Quote Link to comment https://forums.phpfreaks.com/topic/251537-help-in-ajax-call/#findComment-1290103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.