weixin_33681778 2014-09-26 09:32 采纳率: 0%
浏览 46

AngularJS AJAX POST Struts1

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 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 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 Post 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!");
            });
        };

for some reason Angular doesn't like the way i'm sending the ActionForm data.

Please see if you can help. Many thanks :)

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 macOS使用IDEA 2022.2.4打包JDK6项目报错
      • ¥20 OpenCV-Python简单轮廓寻找
      • ¥20 使用matlab进行含参数的最优化求解及数值模拟
      • ¥20 MATLAB找出一维变量中的局部极大值和局部极小值,并进行运算
      • ¥15 有Chang求三维杆单元几何非线性分析matlab代码
      • ¥50 使用unity easyar录屏功能。录屏视频整体色调很暗
      • ¥50 pyinstaller 打包问题
      • ¥15 无法使用cnssc调取网页数据
      • ¥15 Pycharm安装en_core_web_sm失败出现Could not find a version that satisfies the requirement spacy报错
      • ¥15 Python社区划分