cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Can we use AJAX call in Thingworx supported JavaScript editor?

rmote
1-Newbie

Can we use AJAX call in Thingworx supported JavaScript editor?

My actual task is :

1) Execute a URL

2) This URL returns a string.

3) Parse that string & take required values.

For this, I have created a service & wrote following code :

var xmlhttp = new XMLHttpRequest();

xmlhttp.open("POST","http://115.112.176.88:9090/fleetvigil/jsp/maps/ForLocator.jsp?cid=girikandptc&vehicle=9665983265", true);

xmlhttp.send();

 

xmlhttp.onreadystatechange = function()

{

    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)

    {

        var responseStr = xmlhttp.responseText;

        var result = responseStr;

    }

};

After executing this service I got error for :  var xmlhttp = new XMLHttpRequest();

Error is : ReferenceError: "XMLHttpRequest" is not defined. (UrlExe2#3)

Any help is very much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

You don't have XMLHttpRequest object, this is a browser object and TW Embedded Javascript runs at server side on a RINHO engine.

In order to make HTTP calls, you need to go to Snippets section and select "ContentLoaderFunctions" here you have GetJSON, GetText, GetXML ( equivalent to GET operation ), PostJSON, ( equivalent to POST ),....

Carles.

View solution in original post

2 REPLIES 2

Hi,

You don't have XMLHttpRequest object, this is a browser object and TW Embedded Javascript runs at server side on a RINHO engine.

In order to make HTTP calls, you need to go to Snippets section and select "ContentLoaderFunctions" here you have GetJSON, GetText, GetXML ( equivalent to GET operation ), PostJSON, ( equivalent to POST ),....

Carles.

Hi Carles,

Thank you for your immediate reply.

I used "GetText" snippest and it works for me.

kind regards,

Rupesh

Top Tags