POST请求操作表单动态网址角度不起作用

时间:2021-08-15 08:52:37

I am posting a file to the backend using an iframe to avoid a full page load. The action needs to post to a dynamic location based on the users's choice. i.e. depending on what element the user clicks on a different id will be given, which will then change the location of the action of the POST request. When I hard code in the url it works - i.e. www.test.com/1, however when I change the action url dynamically using angular it is not working, although I can see the correct url when I inspect the element, the POST request is not happening. I am using angular version 1.2.1.

我使用iframe将文件发布到后端以避免整页加载。该操作需要根据用户的选择发布到动态位置。即,取决于用户点击不同id的元素,然后将改变POST请求的动作的位置。当我在网址中硬编码时它也可以工作 - 即www.test.com/1,但是当我使用angular动态更改动作网址时它不起作用,虽然我在检查元素时可以看到正确的网址,POST请求没有发生。我正在使用角度版本1.2.1。

Please see my code below

请参阅下面的代码

<iframe id="uploadTrg" name="uploadTrg" height="0" width="0" frameborder="0" scrolling="yes"></iframe>

<form id="myForm" action="{{actionUrl}}" method="post" enctype="multipart/form-data" target="uploadTrg">
   File: <input type="file" name="cv">
   <input type="submit" value="Submit" id="submitBtn"/>
</form>

<div class="role-list" ng-repeat="(key, val) in obj">
    <div ng-repeat="subValue in val track by $index">
       <p class="role" ng-click="getId(subValue.id)">{{subValue.public_name}}</p>
    </div>
</div>

CONTROLLER

$scope.getId = function(id) {
    $scope.actionUrl = 'http://www.test.com/' + id;
}

2 个解决方案

#1


0  

try this:

$scope.getId = function(id) {
    document.myForm.action = 'www.test.com/' + id;
}

"myForm" is the name of the form <form name="myForm>

“myForm”是

形式的名称

#2


0  

Found the answer.

找到了答案。

It is necessary to add the $scope.actionUrl before the function for this to work.

有必要在函数之前添加$ scope.actionUrl以使其工作。

Original answer here.

原来答案在这里。

$scope.actionUrl = '/';

$scope.getApplicationId = function(applicationId) {
    $scope.actionUrl = 'http://www.test.com/' + id;
}

#1


0  

try this:

$scope.getId = function(id) {
    document.myForm.action = 'www.test.com/' + id;
}

"myForm" is the name of the form <form name="myForm>

“myForm”是

形式的名称

#2


0  

Found the answer.

找到了答案。

It is necessary to add the $scope.actionUrl before the function for this to work.

有必要在函数之前添加$ scope.actionUrl以使其工作。

Original answer here.

原来答案在这里。

$scope.actionUrl = '/';

$scope.getApplicationId = function(applicationId) {
    $scope.actionUrl = 'http://www.test.com/' + id;
}