It's all about the answers!

Ask a question

IBM DNG 6.0.5 Custom Widget post values via Rest


Rafael Rodriguez Montes (2181277148) | asked Jul 11, 5:41 p.m.

 Hello, 

I use to work with HttpConnectorParameters in rtc ccm jazz java script, but here when a invoke the library as a feature doesn't exist, so I wonder if there another way to post rest via url in a widget?
Thank you. 


Comments
Davyd Norris commented Jul 11, 6:40 p.m.
What are you trying to do with the calls?

DNG has a more limited API, but the code you write with it runs in the browser, so you can use any JavaScript your browser understands, including HTTP calls

Rafael Rodriguez Montes commented Jul 11, 7:16 p.m.

 I'm trying to integrate with another tool, I'm using 

const Http = new XMLHttpRequest();
const url='rest/post/something';
Http.open("GET", url,false);
Http.send();
$("#results").append("Response: " + Http.responseXML);
but I'm getting null response, Tried with async but I have the feeling that it doesn't refresh once it receive the response and with sync response (true) it doesn't do anything. 

Accepted answer


permanent link
Davyd Norris (4014) | answered Jul 11, 8:02 p.m.
edited Jul 12, 5:47 a.m.
You really should use an asynchronous approach for this but the async/await approach is still not supported by all browsers - or did you mean with the async parameter set to false/true?

I would try with the following and see what you get:
function reqListener () {
  console.log(this.responseXML);
  $("#results").append("Response: " + this.responseXML);
}

const req = new XMLHttpRequest();
req.addEventListener("load", reqListener);
req.open("GET", "rest/post/something");
req.send();

    
Rafael Rodriguez Montes selected this answer as the correct answer

Comments
Rafael Rodriguez Montes commented Jul 11, 8:21 p.m.

 Thank you Davyd, this is what I got after adding your code. blank result, not sure where is failing. 


Davyd Norris commented Jul 11, 8:37 p.m.
Couple of things:
 - check my code, don't use true at the end of the open function
 - can you show the console after the code runs? Do you get anything?
 - can you add console.log(this); to the reqListener function? Let's have a look at the entire response object

Rafael Rodriguez Montes commented Jul 11, 9:12 p.m.
Davyd, thanks for your response, seems like is getting blocked because is not https? is just a request. do you know if can disable this check? or I will have to use https. 


1
Davyd Norris commented Jul 11, 9:36 p.m.
Ah yes OK - you didn't post your actual URL before. You're going to have to switch to a secure call instead.

This is a general issue and has nothing to do with DNG - basically browsers don't like you when you use insecure HTTP calls from inside a secure HTTPS page. This article explains it well:


Rafael Rodriguez Montes commented Jul 12, 4:57 a.m.
Davyds, thanks!

it is working know I can see the response in the console, but in the listener can't recognize the req object, how do I pass the req to the listener ?  


1
Davyd Norris commented Jul 12, 5:44 a.m. | edited Jul 12, 5:49 a.m.

I had a small typo in my previous example code because I copied and pasted yours. Use this instead of req and you should be fine


Rafael Rodriguez Montes commented Jul 12, 6:54 p.m.
thanks, it didn't throw any error, but now, still giving me null, as you can see in the console on the right side I receive the response, but still didn't refresh the widget. 

thank you 


Davyd Norris commented Jul 14, 2:56 a.m.

I can't really see that image, but try console.log(this) instead and see what the whole object is returning.


Rafael Rodriguez Montes commented yesterday

 it is printing in the widget with null if I use this.responseXML and is responding blank if I use just this. 

I printed the response after send in the console and it is responding with the object response, so it is working, but now we need to refresh the widget once the response comes back. 


Rafael Rodriguez Montes commented yesterday

 it works now, I just needed to print as text instead of xml Thank you. 

showing 5 of 10 show 5 more comments

Your answer


Register or to post your answer.