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条回答 默认 最新

  • weixin_33744854 2014-09-26 14:17
    关注

    It is not data that you should use, but params :

    ...
    var responsePromise = $http({
        method: 'POST',
        url: '/BusinessProcess_Project/AjaxSubmit.do',
        // data: formData
        params: formData
    });
    ...
    
    评论

报告相同问题?

悬赏问题

  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路