CodeIgniter Forums
Make a list with ajax and php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Make a list with ajax and php (/showthread.php?tid=55240)



Make a list with ajax and php - El Forum - 10-16-2012

[eluser]Diegosf93[/eluser]
Hi, i have this problem i want to make a list of images with ajax look this:

Controller
Code:
public function List_Image($id="")
{

if($this->input->post("enviar"))
    {
  echo $id;

}else {
  $data['contenido']= $this->load->view('Panel_Admin/List_Image',true);
  $this->load->view('template', $data, FALSE);

  }

}

This is only a test i´m not going to the db only want to show the id.

View

Code:
<select name="" id="region">

<option value="1">Europa</option>
<option value="2">America</option>

</select>


<div id="city">

// Dynamic select

</div>
<div id="a">

</div>

<a href="[removed]void(0)">Listar</a>

JS

Code:
function Mostrar(){
var id=$("#region").val();
  
$.post("List_Image/"+id,{id:id},function(respuesta){
$("#a").html(respuesta);
  
});
  

};

When i click de button the only thing that it do is show me the view duplicate and nothing more, please help me.

Thanks


Make a list with ajax and php - El Forum - 10-16-2012

[eluser]CroNiX[/eluser]
Are you using routes or something? Because the url you are sending the request to is only the method name List_Image with no controller name?
Code:
$.post("List_Image/"+id,{id:id},function(respuesta){

Are you using htaccess to remove index.php from the URL? If not, that needs to be a part of the URL as well.

Code:
$.post("http://yoursite.com/index.php/controller/List_Image/"+id,{id:id},function(respuesta){