Hi,

I am trying to  call to login api from ajax client.It is hitting the server.

Here I can only connect to the server.Is this process correct?Or should do any further improvements?I need the output in a json format.

I am sharing my code snippet used.

//controller.xml

 <request-map uri="login">
        <security https="true" auth="false"/>
        <event type="java" path="org.apache.ofbiz.webapp.control.LoginWorker" invoke="login"/>
        <response name="success" type="view" value="main"/>
        <response name="requirePasswordChange" type="view" value="requirePasswordChange"/>
        <response name="error" type="view" value="login"/>
        <response name="response" type="request" value="json" />
    </request-map>

Sample ajax code:


<head>
LOGIN AUTHENTICATION
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js";></script>

</head>

<body>
<br>

Username: <input type="text" name="username" value="admin" id="na"><br>
Password: <input type="password" name="password" value="ofbiz" id="pa"><br>
          <button name="login" id="login">Login</button>

<script>



$("#login").click(function(){

    var username = $('#na').val();
    alert("user"+ username);
    var password = $('#pa').val();
    alert("pass" +password);
    $.ajax({
        url: 'https://localhost:8443/ordermgr/control/login.json',
        type:"POST",
        datatype : "application/json",
        //contentType: "text/plain",
        contentType: "json",
        data: {username:username,password:password},

        success: function() {
        alert("success");
        window.location.href = "https://localhost:8443/ordermgr/control/login.";;
        return true;

    },
          error: function(){
          alert("wrong data");
          }

    });
});


</script>

</body>
</html>




Kind Regards,

Rakhee Mohan.I



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

Reply via email to