dp0518 2013-12-30 14:59
浏览 74

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

I am new to codeigniter , I am trying to call a controller on AJAX call sucess... I tried to search stackoverflow but i didn't get what i needed..

Form in my view

<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>

When the form is submitted the below java script is executed.

JavaScript in my View

 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 call works successfully , I can see the returned data in the alert (Returned data is JSON encoded)

Now i want to call another controller with the recieved data ... Please help me to figure this out

  • 写回答

2条回答 默认 最新

  • dua27031 2013-12-30 15:04
    关注

    you just need to redirect the control the required controller :

    success: function(data)
                {
    
                  window.location.href="http://localhost/my_project_name/my_controller_name";// you just need to add this event on success call.
    
                },
    
    评论

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀