Using AngularJS for Ajax POST in Struts 1
Using AngularJS for Ajax POST in Struts 1
我正在尝试使用Struts操作表单发送Ajax POST。
我已经成功地使用jQuery创建了这种调用。
ActionForm
:
public class AjaxForm extends ActionForm {
private static final long serialVersionUID = 7403728678369985647L;
private String name = null;
private FormFile uploadedFile = null;
public FormFile getuploadedFile() {
return uploadedFile;
}
public void setFile(FormFile uploadedFile) {
this.uploadedFile = uploadedFile;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Action
:
public class AjaxAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
AjaxForm ajaxForm = (AjaxForm)form;
System.out.println("Hello " + ajaxForm.getName());
jQuery Ajax POST(工作):
<script src="/BusinessProcess_Project/jquery.js"></script>
<script type="text/javascript">
function doAjaxPost() {
// get the form values
//var name = $('#name').val();
var formData ={
'name':'jQuery_Oron'
};
$.ajax({
type: "POST",
url: "/BusinessProcess_Project/AjaxSubmit.do",
// data: "name=" + 'jQuery',
data:formData,
dataType: "text/json",
success: function(response){
},
error: function(e){
alert('Error: ' + e);
}
});
}
</script>
AngularJS Ajax POST(不工作):
<script type="text/javascript">
$scope.myShabi = {};
$scope.myShabi.doClick = function(item, event) {
// $scope.init = function(item, event) {
$scope.loading = true;
var formData ={
'name':'Angular_Oron'
};
var responsePromise = $http({
method: 'POST',
url: '/BusinessProcess_Project/AjaxSubmit.do',
data: formData
});
responsePromise.success(function(data, status, headers, config) {
$scope.jsonFromServer = data;
$scope.status ="Finished";
$scope.loading = false;
});
responsePromise.error(function(data, status, headers, config) {
alert("AJAX failed!");
});
};
</script>
出于某种原因,AngularJS不喜欢我发送ActionForm
数据的方式。
应该使用的不是data
,而是params
:
...
var responsePromise = $http({
method: 'POST',
url: '/BusinessProcess_Project/AjaxSubmit.do',
// data: formData
params: formData
});
...
相关文章:
- Node.js's Buffer.writeFloatBE in Javascript
- 从JavaScript访问struts操作中的属性
- Setting default onclick behavior for <img> tag in gene
- Lucene Search in Alfresco
- grep in JQuery to C#
- write HTML in JavaScript
- jQuery setTimeOut: in for-loop
- SetTimeout and clearTimeout in Javascript
- lightbox in html 5 and javascript
- HTMLInputElement in IE7
- Mongodb$in以与数组中相同的顺序获取结果
- element.dataset in Internet Explorer
- 用Java/Struts/Spring项目实现Visual Captcha
- jQuery parent() in table
- Instagram oauth flow in angularjs
- In循环的In运算符前后
- 如何使用for in循环在javascript中显示对象中的对象
- Jquery change onchange in onload
- 重构 jQuery in JS 问题
- Using AngularJS for Ajax POST in Struts 1