Welcome Guest, Not a member yet? Register   Sign In
Make a list with ajax and php
#1

[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
#2

[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){




Theme © iAndrew 2016 - Forum software by © MyBB