Jump to content

Ajax help


vikrantmohite

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.