你好,我有一个函数,我正在使用 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,它是包含值“借用”的参数,这是我调用以发送此表单的 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 的值并将 borrowed 代替 borrow。
我尝试了很多方法,例如 .submit(borrowed),但这些方法都不起作用,所以基本上我只想将路径名内的不同值发送到接收此参数的 Controller 。
最佳答案
就在您提交之前,您可以添加这样的属性
$("#register_form").attr('action',BASEURL + "index.php/bla/bla/borrowed");
然后当您提交时,它将作为参数附加在后面。
关于javascript - 在 .submit 中发送一个额外的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38848621/