【问题标题】:Two different actions on one button一个按钮上的两种不同操作
【发布时间】:2013-08-07 06:32:52
【问题描述】:

我在视图中创建了一个表单,该表单调用了控制器中的某些方法。 我想在提交按钮功能上做两件事:

使用Ajax函数在同一页面上显示输出,

使用 $this->input->post 函数获取数据(以与显示输出相同的方法)

【问题讨论】:

  • 要么使用Ajax,要么使用传统的get,post函数。
  • 我解决了我的问题。我不得不使用 iframe。谢谢。

标签: ajax codeigniter jquery codeigniter-2


【解决方案1】:

你可以在你的按钮上写两个函数...对于type="button"

<input type="button" value="Don't show this again! " onclick="function1();function2();" />

【讨论】:

    【解决方案2】:

    你可以像这样使用 ajax:

    $.ajax({
        url: "Here is the url path",
        type: "GET",
        data: {},
        beforeSend:function(){
            //do something like loading image
        },
        success:function(response){
            alert(response); //do something
        },
        error:function(e){
            alert("something wrong"+e);
        }
    })
    

    【讨论】:

    • 在 beforeSend 函数中,我想在我的控制器中调用一个方法,并且该方法通过 this->input->post() 使用表单值,我如何使用 this->input 获取值->发布?
    • @Aman 将 type:GET 替换为 type:POST 然后你就可以在 post 中获取值了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多