Problems with Servlet access through Ajax call

0

Good morning, everyone, to see if someone could give me a hand to solve a problem I'm having.

I'm trying to access a Java Servlet from an Ajax call via JavaScript, until then everything would fit, but when I make the call to the Servlet it returns the following error:

  

Uncaught TypeError: jQuery.ajax is not a function

I put the code to be placed:

In an Event onClick() I call the function that makes the call Ajax Servlet.

        onClick: function() {
            this.ConectaServlet();
          },
        ConectaServlet: function() {

          var pOrigen = this.getView().byId("idButton1").getText();
          var oParameters = {
             "pOrigen": pOrigen
          };

          if (pOrigen) {

               this.doAjaxConecta("Conecta", oParameters, "POST", true)
                .success(function(data, textStatus, jqXHR) {
                    oModel.setData(data);
                })
                .error(function(jqXHR, textStatus, errorThrown) {
                    if(jqXHR.status && jqXHR.status != 200) {
                        jQuery.sap.require("sap.m.MessageBox");
                        sap.m.MessageBox.alert("Error producido al acceder 
                          al Servlet: "+jqXHR.responseText);
                    } 
                    else {
                        jQuery.sap.require("sap.m.MessageBox");
                        sap.m.MessageBox.alert("producido al acceder al 
                           Servlet: "+jqXHR.responseText);
                    }           
                })
                .complete(function(jqXHR, textStatus) {
                    errores = this.tratamientoMensajesRetorno(oModel);
                })

           } 
         },

   doAjaxConecta: function(action, content, type, async) {      
        var serviceURL = this.getUrl(SERVICE_PATH + 
                         "pruebaServlet?action=");

        var params = {
                url: serviceURL + action,
                dataType: "json",
                beforeSend: function() {
                    try {
                        //var oBusyIndicator =
                        // sap.ui.getCore().byId("idBusyIndicator");
                        // oBusyIndicator.setVisible(true);
                    } catch(e){

                    }
                },
                contentType: "application/json",
                context: this,
                cache: false
        };

        params["type"] = type || "POST";

        if (async === false) {
            params["async"] = async;
        }

        if (content) {
            params["data"] = JSON.stringify(content);
        }

        return jQuery.ajax(params);
    },      

    getUrl : function(sUrl) {
        if (sUrl == "")
            return sUrl;
        if (window.location.hostname == "localhost") {
            return "proxy" + sUrl;
        } else {
            return sUrl;
        }
    }

The problem I get when I run the application and access the call doAjaxConecta where jQuery.ajax(params); does not recognize me. Someone could give me some clue why I miss this error.

    
asked by Fco Javier 25.08.2017 в 14:45
source

1 answer

0

Good morning Javier Domínguez Pérez, I have tried to include the jquery script in the html page, in the following way:

<!DOCTYPE HTML>

                      

    <script src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js"
            id="sap-ui-bootstrap"
            data-sap-ui-libs="sap.m"
            data-sap-ui-theme="sap_bluecrystal"
            data-sap-ui-compactVersion="edge"
            data-sap-ui-resourceroots='{"conexionapplet": ""}'>
    </script>

    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>

        <script>
        sap.ui.getCore().attachInit(function() {
            new sap.m.Shell({
                app: new sap.ui.core.ComponentContainer({
                    height : "100%",
                    name : "conexionapplet"
                })
            }).placeAt("content");
        });
    </script>

</head>
<body class="sapUiBody" id="content">
</body>

Then I run again and it tells me the same error again:      Uncaught TypeError: jQuery.ajax is not a function.

Where should I indicate the jQuery Script, on the html page or where do I call the onClick () event?.

Greetings.

    
answered by 26.08.2017 в 09:52