Dojo xhrPost ajax call not response

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mgdvicky
    New Member
    • Feb 2014
    • 12

    Dojo xhrPost ajax call not response

    If i submit a form, there is no interaction between ajax&servlet.

    Code:
    function postform() {
                   var xhrArgs= {
                            url: "../Ajaxss",
                            form: dojo.byId("myForm"),
                            load: function (message) {
                            dojo.byId("Message").innerHTML = "<div style=\"color:green\">"+message+"</ div>";
                            },
                            error: function (error) {
                                    console.error ('Error: ', error);
                            }
                    };    
        			var deferred = dojo.xhrPost(xhrArgs);
            }
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    Maybe your URL is wrong?
    You gave "../Ajaxss" as your URL.
    Just use an absolute address instead of a relative one for testing. Maybe it goes to the wrong directory.
    Also check if your servlet "Ajaxss" is really inside this directory and the server allows clients to access it, especially execute permissions.

    Comment

    • mgdvicky
      New Member
      • Feb 2014
      • 12

      #3
      Thank you chaarmann. I'm using this URL also, http://localhost:8080/FinalChapter/Ajaxss. but there is no interaction between ajax.
      If i am using action attribute in form tag it'll works fine to interact with servlet, but not with ajax..
      servlet code:
      Code:
      public class Ajaxss extends HttpServlet {
      	private static final long serialVersionUID = 1L;
      
      	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      		 PrintWriter out=response.getWriter();
               String	name=request.getParameter("myName");
               out.println("hello" + name + "Welcome!");
      	}
      }
      html code:
      Code:
      <script>
      			dojoConfig={parseOnLoad: true, isDebug: false}
      			</script>
      			<script src='../dojoctr/dojo/dojo.js'></script>
      			<script src='JsFiles/ajaxpost.js'></script>
      			<script>
      				require(["dojo/parser",
      				         "dojo/_base/xhr",
      				         "dijit/form/TextBox",
      				         "dijit/form/Button",
      				         "dijit/form/Form"				         
      				       ]);
      			</script>
      	</head>
      	<body class="claro">
                <form data-dojo-type="dijit/form/Form" name="myForm" id="myForm" method="post">
                <h3> Example of using xhrpost</h3><br>
                <label for="Name">Enter your Name:</label>
                <input type='text' data-dojo-type="dijit/form/TextBox" name='myName' id="myName"/>
                <button data-dojo-type="dijit/form/Button" type="submit" name="submit" value="submit" onclick="postform()">submit</button>
                </form>
                <div id='Message'></div>
          </body>
      </html>
      [/CODE]

      Comment

      • chaarmann
        Recognized Expert Contributor
        • Nov 2007
        • 785

        #4
        If i am using action attribute in form tag it'll works fine to interact with servlet, but not with ajax.
        Then the problem is not Java related. It's Javascript related and for that you should ask for better help in a Javascript or even better Dojo forum.
        I have programmed an Ajax test in Dojo where I call a sevlet and it worked, but I have used a different method "request" which is described in dojotoolkit.org documentation "Ajax with dojo/request". So try it out with your sevlet. If it works, then the problem is not server side related, but client side.
        As a general advice, you should insert console.log() message at every line of your Dojo program and see in Firebug if the request is really made. (especially one inside function postform). Firebug has a tab where you can see all requests and its status.
        If the request was made at all, show inside your Apache (or IIS or whatever server you have) logs if it really arrives and will be processed or will be rejected as an error.

        Comment

        • mgdvicky
          New Member
          • Feb 2014
          • 12

          #5
          sure. chaarmann thanks a lot for your valuable response.

          Comment

          Working...