在.submit中发送一个额外的参数

sending a extra parameter in .submit

本文关键字:一个 参数 submit      更新时间:2023-09-26

你好,我有一个函数,我使用ajax来尝试得到一些值,然后提交一个php表单,看起来像这样。

/* form-horizontal */
    $attributes = array("class" => "form-horizontal", "id" => "register_form");
    if (isset($_SESSION['login'])) 
    {
        if ($_SESSION['login'] == 'DoBusinessPerformed' || $_SESSION['login'] == 'NormalPerformed') {                
            echo form_open('myprofile/ManageProcessNew/'.$pathName, $attributes);
        } else {
            echo form_open('myprofile/RegisterProcessNew/'.$pathName, $attributes);
        }
    } 
    else 
    {
        echo form_open('myprofile/RegisterProcessNew/'.$pathName, $attributes); 
    }   

正如你所看到的,我有一个。$pathname,这是一个参数,包含值'borrow',这是ajax函数,我正在调用来发送这个表单。

 self.checkMangoPayId = function(){
            $.ajax({
                type: 'POST',
                url: BASEURL + 'index.php/myprofile/checkMangoPayID/' + auth,
                contentType: 'application/json; charset=utf-8',
            })
            .done(function(data) {
                console.log(data);
               if(data.mangopay_id == null){
                   alert("going to save page for mango id");
                   // here is where I submit the form
                   $("#register_form").submit();
               }else{
                   self.mangoPayIdCheck(true);
                   self.showModalAddId();
               }
            })
            .fail(function(jqXHR, textStatus, errorThrown) {
                alert("Error code thrown: " + errorThrown);
            })
            .always(function(data){
            });
        }

我想做的是在。submit函数中添加一种方法来更改。$path name的值,并将借来的而不是借来的

我尝试了很多方法,比如。submit(borrow),但这些方法都不起作用,所以基本上我想在pathname内部发送一个不同的值给我的控制器,它接收这个参数

在提交之前可以添加这样的属性

$("#register_form").attr('action',BASEURL + "index.php/bla/bla/borrowed");

然后当你提交的时候它会作为参数附在后面