开发者

Codeigniter controller don't return back value to view through jquery

开发者 https://www.devze.com 2023-03-08 03:03 出处:网络
i have a folder structure like that in codeigniter +asset +css +js +jquery jquery.js global.js +application

i have a folder structure like that in codeigniter

 +asset
 +css
 +js
   +jquery
     jquery.js
     global.js
+application
+system

So i guess you figure out the rest of the structure. Now i have this view like that:

<li>
        <label>Pa&iacute;s</label>
        <div>
            <select name="pais" id="pais">
                <option value="" selected="selected"> -- Selecciona un pa&iacute;s</option>
                <?php foreach($thesex as $pais):?>
                    <option value="<?php echo $pais->pais_id; ?>"><?php echo ascii_to_entities($pais->pais_descrip); ?></option>
                <?php endforeach;?>
            </sel开发者_如何学运维ect>
        </div>
    </li>

    <li id="esta">
        <label>Estado</label>
        <div>
            <select name="estad" id="estad">

            </select>
        </div>
    </li>

and my controller is as follow:

function estado_paisout()
{
    $this->output->set_status_header(200);
    $this->output->set_header('Content-type: application/json');
    $done = $this->input->post('pid');
    $est = $this->Estado_model->estado_paisout($done);
    echo json_encode($est);
}

and my jquery code is:

$("#pais").change(function(){
    var id = $(this).val();
        $("#esta").show();
        $.ajax({
        type: "POST",
        url: base_link+"/am_registr/ciudad/estado_paisout",
        dataType: "json",
        data: {'pid': id},
        success: function(xhr){
            alert(xhr);
            },
        error : function(xhr, status, error){
            alert(xhr.responseText);
            }   
        });     
    return false;
});

So the issue is that this is returning a 404 error page saying that this page cannot be found. When i try to echo a simple "Hello" from the controller, it gives the same error. But when i try the full link "localhost/mysite/index.php/am_registr/ciudad/estado_paisout" in the browser, it tells me that is an applicatio/json file, so when i save it and try to open it with notepad, i got the "Hello".

Any help is welcome..!


not sure, i would examine either your config/routes to make sure that it can handle

am_registr/ciudad/estado_paisout

i think the default would be to treat

  • am_registr as controller
  • ciudad as action (method) name
  • estado_paisout as a param...

whereas you're treating estado_paisout as the action name.

i'd also look at is to make sure you're mod_rewrite is working on localhost

and that the .htaccess file which code igniter uses to remove the index.php from URLs is working


HI David Chan,
I got to tell you that i resolved the issue and i guess it's just beacuse in the jquery function i declare the variable base_link = "localhost/mysite/index.php", instead of having it like that: base_link = "http://localhost/mysite/index.php". So thanks for your help..!

0

精彩评论

暂无评论...
验证码 换一张
取 消