codeigniter在ajax调用成功时调用视图/控制器

时间:2013-12-30 14:59:14

标签: javascript php jquery ajax codeigniter

我是codeigniter的新手,我试图在AJAX调用成功时调用一个控制器... 我试图搜索stackoverflow但我没有得到我需要的东西..

在我看来表格

<form onsubmit="categorysearch()" method="GET">



                <label for="username">Category : </label>
                <select id="category" name="category">
                    <option value="android">android</option>
                    <option value="iphone">iphone</option>
                    <option value="windowsphone">windowsphone</option>
                    <option value="blackberry">blackberry</option>

                </select>


                <input type="submit" name="searchkeywordsubmit" title="Search" id="searchkeywordsubmit" />


            </form>

提交表单时,将执行以下java脚本。

我视图中的JavaScript

 function categorysearch()
        {
            var categorykeyword = document.getElementById("category").value;
            alert("Category keyword is " + categorykeyword);


            $.ajax({
                type: "GET",
                async: false,
            //dataType: "json",
            url: "http://localhost/2009074/index.php/rest/resource/categorysearch/category/" + categorykeyword + "",
            success: function(data)
            {

               alert("Returned data is " + data);
               // i want to call the constructor here with the returned data


                //$("body").html(data);

                //$('body').append(output_string);


            },
            error: function(data)
            {
                alert("error is " + data);
            }

        });
    }

AJAX调用成功,我可以看到警报中返回的数据(返回的数据是JSON编码的)

现在我想用收到的数据调用另一个控制器...... 请帮我解决这个问题

2 个答案:

答案 0 :(得分:0)

您只需要将控件重定向到所需的控制器:

success: function(data)
            {

              window.location.href="http://localhost/my_project_name/my_controller_name";// you just need to add this event on success call.

            },

答案 1 :(得分:0)

一种非常脏的方法是将JSON对象保存为会话变量并导航到页面或重新加载页面,并在页面的构造函数中检查会话变量并使用变量。

好吧,这是我现在能想到的唯一方法。

相关问题