1
我想使用Struts动作表单发送ajax文章。 我已经成功使用jQuery创建这种类型的调用。AngularJS AJAX POST Struts1
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的阿贾克斯邮政工作:
<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阿贾克斯后notWorking:
$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!");
});
};
出于某种原因角不喜欢我送的ActionForm的数据的方式。
请参阅是否可以帮忙。 非常感谢:)
你得到什么错误?顺便说一句,我认为你应该链接成功和错误,以避免不必要的查找。 'var responsePromise = $ http(...)。success(...)。error(...)' – laruiss 2014-09-26 10:01:47
嗨,感谢您的更新,我没有收到错误,只是得到:'你好null' – 2014-09-26 12:00:23
如果添加'responseType:“json”'会怎么样? 变种responsePromise = $ HTTP({ 方法: 'POST', URL: '/BusinessProcess_Project/AjaxSubmit.do', 数据:FORMDATA, 的responseType: “JSON” }); – laruiss 2014-09-26 12:11:05