473,503 Members | 722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dojo xhrPost ajax call not response

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

Expand|Select|Wrap|Line Numbers
  1. function postform() {
  2.                var xhrArgs= {
  3.                         url: "../Ajaxss",
  4.                         form: dojo.byId("myForm"),
  5.                         load: function (message) {
  6.                         dojo.byId("Message").innerHTML = "<div style=\"color:green\">"+message+"</ div>";
  7.                         },
  8.                         error: function (error) {
  9.                                 console.error ('Error: ', error);
  10.                         }
  11.                 };    
  12.                 var deferred = dojo.xhrPost(xhrArgs);
  13.         }  
  14.  
Mar 17 '14 #1
4 2696
chaarmann
785 Recognized Expert Contributor
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.
Mar 17 '14 #2
mgdvicky
12 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. public class Ajaxss extends HttpServlet {
  2.     private static final long serialVersionUID = 1L;
  3.  
  4.     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  5.          PrintWriter out=response.getWriter();
  6.          String    name=request.getParameter("myName");
  7.          out.println("hello" + name + "Welcome!");
  8.     }
  9. }
  10.  
html code:
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.             dojoConfig={parseOnLoad: true, isDebug: false}
  3.             </script>
  4.             <script src='../dojoctr/dojo/dojo.js'></script>
  5.             <script src='JsFiles/ajaxpost.js'></script>
  6.             <script>
  7.                 require(["dojo/parser",
  8.                          "dojo/_base/xhr",
  9.                          "dijit/form/TextBox",
  10.                          "dijit/form/Button",
  11.                          "dijit/form/Form"                         
  12.                        ]);
  13.             </script>
  14.     </head>
  15.     <body class="claro">
  16.           <form data-dojo-type="dijit/form/Form" name="myForm" id="myForm" method="post">
  17.           <h3> Example of using xhrpost</h3><br>
  18.           <label for="Name">Enter your Name:</label>
  19.           <input type='text' data-dojo-type="dijit/form/TextBox" name='myName' id="myName"/>
  20.           <button data-dojo-type="dijit/form/Button" type="submit" name="submit" value="submit" onclick="postform()">submit</button>
  21.           </form>
  22.           <div id='Message'></div>
  23.     </body>
  24. </html>
  25.  
[/code]
Mar 17 '14 #3
chaarmann
785 Recognized Expert Contributor
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.
Mar 17 '14 #4
mgdvicky
12 New Member
sure. chaarmann thanks a lot for your valuable response.
Mar 17 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5214
by: Zeba | last post by:
Hi guys! I'm new to JS / Ajax; I've been trying to do an Ajax call to my Webservice ( I'm using C# for code-behind). I'm not using any of the libraries available. I am sending my CustID to the...
3
2055
by: wendallsan | last post by:
Hi All, I've stumped myself writing an app that uses Prototype and a bit of PHP. Here is what I have: I have a custom class named Default_county_init_data that, upon initialization makes...
2
4624
by: gaya3 | last post by:
Hi , can any one please say me how to retreive the array from another jsp thro' ajax call... <%@ include file="JspBean.jsp" %> <html> <head> <link rel="stylesheet" type="text/css"...
3
1861
by: rbansalit | last post by:
Hi all I am making a very simple ajax call. But I am not getting any message from sever. <html> <body> <script type="text/javascript"> function ajaxFunction()
9
37250
Claus Mygind
by: Claus Mygind | last post by:
I am having trouble escaping the & in a JSON.stringfy() ajax call. I don't even know if I am stating the problem correctly here. In my app I have linked json2.js from http://www.JSON.org/json2.js...
5
8786
by: samarinder | last post by:
I am displaying the results by iterating the list in div tag say "results" in my case.For refining of search i am using ajax call. But when i am getting response back from this below snippet ...
6
2354
by: agam | last post by:
Here is my ajax call: new Request.HTML({ url: 'users.html', method: 'get', update: 'go', evalScripts: true, /* !! Why isn't this working!? */ onComplete:...
4
1442
Claus Mygind
by: Claus Mygind | last post by:
Is is possible in a php server side app. to both return a success or failure notice to the client app and also send downloaded information to a new client app. Problem: 1) send an ajax request...
6
5090
by: rakesh2k78 | last post by:
Hi All, I have a requirement where I need to fire an ajax call(dojo xhrPost)on click of an anchor, but as soon as I click the anchor link browser starts to redirect but ajax call is not finished...
0
2777
by: varunkumarid | last post by:
I have tried to download the file from the server through the webmethod but it has not work for me. my code as below public static string GetServerDateTime(string msg) { String result =...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.