AngularJS AJAX POST Struts1 [英] AngularJS AJAX POST Struts1
本文介绍了AngularJS AJAX POST Struts1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Struts操作表单发送ajax帖子.我已经成功使用jQuery创建了此类调用.
I'm trying to send ajax post using Struts action form. I've succeeded to create this kind of call using jQuery.
Struts1 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;
}
}
Struts1操作:
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 Working:
<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发布无效:
$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!");
});
};
由于某些原因,Angular不喜欢我发送ActionForm数据的方式.
for some reason Angular doesn't like the way i'm sending the ActionForm data.
请查看是否可以提供帮助.非常感谢:)
Please see if you can help. Many thanks :)
推荐答案
您不应使用 data
,而是 params
:
...
var responsePromise = $http({
method: 'POST',
url: '/BusinessProcess_Project/AjaxSubmit.do',
// data: formData
params: formData
});
...
这篇关于AngularJS AJAX POST Struts1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文