0

xhrPost seems to be modifying the URL resulting in either 404 or 405. This is from a custom widget and attempting to go to a REST service on a WebSphere Liberty server.

The rest service responds correctly when using RESTClient and building the request manually.

I am using var jsonData = JSON.stringify(domForm.toObject("TaskTemplate")); so I can verify the data is correct and sending the data as that string: data: jsonData,

the URL is hardcoded in the form and no substitution is currently being used:

 <form  id="TaskTemplate" name="TaskTemplate" 
 data-dojo-attach-point="taskTemplateNode" 
 method="POST" 
 action="http://localhost:9080/test2/rm/tasks/64/update">

I also have a GET with a URL of "http://localhost:9080/test2/rm/tasks/64/" that is working fine. Seems to be associated with PUT or POST...

When I do the xhrPost, I am getting the following error: "NetworkError: 404 Not Found - http://localhost:9080/test2/undefined"

since "undefined" is seen, it is like xhrPost is doing some substitution in the hardcode URL... I am using 1.9.2-20140219-IBM version of dojo which comes with Rational Application Developer. I have tried both xhrPost and xhrPut with the same results.

Here is the method that is invoked when the button is pushed:

 applySubmit: function() { 
         console.log("inside applySubmit");
         var jsonData = JSON.stringify(domForm.toObject("TaskTemplate"));
         console.log(jsonData);
         var xhrArgs = {
          // url: "http://localhost:9080/test2/rm/tasks/64/update",
          data: jsonData, 
          preventCache: true,
          timeout: 10000,
          handleAs: "text",
          contentType: "application/json",
          load: function(data) {
              console.debug("applySubmit success:" + data);
          },
          error: function(data) {
              console.debug("applySubmit error:");
          }
      };
 console.log("doing dojo.xhrPxxx(xhrArgs);");
 var deferred = dojo.xhrPost(xhrArgs);  // any need to save local var and exit?
 }

In the server logs, I am seeing [WARNING ] SRVE0190E: File not found: /undefined and that is coming from the webcontainer (makes sense given the error msg above) So, this means it is not related to my rest service, never gets to it.

This is really starting to delay our project, so any ideas about why this might be occurring would be greatly appreciated!

Jay Witherspoon
  • 165
  • 1
  • 11
  • 1
    As per the [xhrPost](http://dojotoolkit.org/reference-guide/1.9/dojo/xhrPost.html) document the argument to `xhrArgs` for data is `postData` and **not** `data`. Try to change the attribute of `xhrArgs` from `data` to `postData`. – frank Jul 11 '15 at 08:19
  • 2
    In the code you provided, `url` is commented out, which would result in `xhrPost` stringifying `undefined` and requesting that relative to the same path of the page you're viewing. Are you sure that isn't your problem? – Ken Franqueiro Jul 11 '15 at 20:24
  • 1
    I would like to thank both Frank and Ken. I am now getting the correct URL and I am getting to my REST service! – Jay Witherspoon Jul 11 '15 at 22:28

0 Answers0