<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Unable to get proper response in ajax call, returning HTML response instead json. in ThingWorx Developers</title>
    <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/629302#M39612</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to bring a custom chart&amp;nbsp; in thingworx, It is a out of the scope of thingworx widgets so am developing it&amp;nbsp; using HTML,JS and viewing through webframe widget. Whenever I call thingworx services it is returning HTML response instead json. Please find the sample code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;BR /&gt;&amp;lt;html&amp;gt;&lt;BR /&gt;&amp;lt;head&amp;gt;&lt;BR /&gt;&amp;lt;script src="&lt;A href="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js&amp;quot;&amp;gt;&amp;lt;/script" target="_blank" rel="noopener"&gt;https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"&amp;gt; &amp;lt;/script&lt;/A&gt;&amp;gt;&lt;BR /&gt;&amp;lt;/head&amp;gt;&lt;BR /&gt;&amp;lt;body&amp;gt;&lt;BR /&gt;&amp;lt;button onclick="callme()"&amp;gt;click&amp;lt;/button&amp;gt;&lt;BR /&gt;&amp;lt;p id="results"&amp;gt;check here&amp;lt;/p&amp;gt;&lt;BR /&gt;&amp;lt;script&amp;gt;&lt;BR /&gt;function callme(){ &lt;BR /&gt;$.ajax({&lt;BR /&gt;type: 'POST',&lt;BR /&gt;contentType: "application/json;charset=utf-8",&lt;BR /&gt;accept: "application/json;charset=utf-8",&lt;BR /&gt;url : 'https://localhost:8443/Thingworx/Things/test/Services/parseData',&lt;BR /&gt;success: function(response){&lt;BR /&gt;console.log(response); &lt;BR /&gt;$("#results").append(response.result);&lt;BR /&gt;}&lt;BR /&gt;}); &lt;BR /&gt;}&lt;BR /&gt;&amp;lt;/script&amp;gt;&lt;BR /&gt;&amp;lt;/body&amp;gt;&lt;BR /&gt;&amp;lt;/html&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here, The service&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;parseData()&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;is returning HTML response though the accept type json. I could able to get json response in postman.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know what went wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Janakiraman P&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2019 06:10:39 GMT</pubDate>
    <dc:creator>Janakiraman-P</dc:creator>
    <dc:date>2019-10-03T06:10:39Z</dc:date>
    <item>
      <title>Unable to get proper response in ajax call, returning HTML response instead json.</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/629302#M39612</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to bring a custom chart&amp;nbsp; in thingworx, It is a out of the scope of thingworx widgets so am developing it&amp;nbsp; using HTML,JS and viewing through webframe widget. Whenever I call thingworx services it is returning HTML response instead json. Please find the sample code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;BR /&gt;&amp;lt;html&amp;gt;&lt;BR /&gt;&amp;lt;head&amp;gt;&lt;BR /&gt;&amp;lt;script src="&lt;A href="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js&amp;quot;&amp;gt;&amp;lt;/script" target="_blank" rel="noopener"&gt;https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"&amp;gt; &amp;lt;/script&lt;/A&gt;&amp;gt;&lt;BR /&gt;&amp;lt;/head&amp;gt;&lt;BR /&gt;&amp;lt;body&amp;gt;&lt;BR /&gt;&amp;lt;button onclick="callme()"&amp;gt;click&amp;lt;/button&amp;gt;&lt;BR /&gt;&amp;lt;p id="results"&amp;gt;check here&amp;lt;/p&amp;gt;&lt;BR /&gt;&amp;lt;script&amp;gt;&lt;BR /&gt;function callme(){ &lt;BR /&gt;$.ajax({&lt;BR /&gt;type: 'POST',&lt;BR /&gt;contentType: "application/json;charset=utf-8",&lt;BR /&gt;accept: "application/json;charset=utf-8",&lt;BR /&gt;url : 'https://localhost:8443/Thingworx/Things/test/Services/parseData',&lt;BR /&gt;success: function(response){&lt;BR /&gt;console.log(response); &lt;BR /&gt;$("#results").append(response.result);&lt;BR /&gt;}&lt;BR /&gt;}); &lt;BR /&gt;}&lt;BR /&gt;&amp;lt;/script&amp;gt;&lt;BR /&gt;&amp;lt;/body&amp;gt;&lt;BR /&gt;&amp;lt;/html&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here, The service&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;parseData()&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;is returning HTML response though the accept type json. I could able to get json response in postman.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know what went wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Janakiraman P&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 06:10:39 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/629302#M39612</guid>
      <dc:creator>Janakiraman-P</dc:creator>
      <dc:date>2019-10-03T06:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to get proper response in ajax call, returning HTML response instead json.</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/631725#M39971</link>
      <description>&lt;P&gt;Hello Janakiraman,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out on the ThingWorx Developer Community.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Firstly, I do apologize for the delay in reply to your post. Were you able to workaround this as of yet?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not, my initial recommendation is to simply try excluding the charset=utf-8 from both contentType and Accept.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should this not work for you please provide the contents of the response you are getting. Is it the expected response just in HTML form or is there perhaps an error being returned?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Tyler Misner&lt;/P&gt;
&lt;P&gt;ThingWorx Technical Support Engineer&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 19:12:20 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/631725#M39971</guid>
      <dc:creator>tmisner</dc:creator>
      <dc:date>2019-10-16T19:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to get proper response in ajax call, returning HTML response instead json.</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/631795#M39982</link>
      <description>&lt;P&gt;Hello ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your response. I gone thru some workaround and got relevant solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;var&amp;nbsp;chartData;&lt;/P&gt;
&lt;P&gt;$.ajax({&lt;BR /&gt;type: 'POST',&lt;BR /&gt;url : 'https://&amp;lt;domain&amp;gt;:8443/Thingworx/Things/test/Services/getDataForChart',&lt;BR /&gt;dataType:"json",&lt;BR /&gt;crossDomain:true,&lt;BR /&gt;contentType:"application/json;charset=utf-8", &lt;BR /&gt;async:false,&lt;BR /&gt;success: function(data, textStatus, jqXHR)&lt;BR /&gt;{&lt;BR /&gt;chartData=data;&lt;BR /&gt;console.log(chartData.rows);&lt;BR /&gt;},&lt;BR /&gt;error: function (jqXHR, textStatus, errorThrown)&lt;BR /&gt;{&lt;BR /&gt;alert("error");&lt;BR /&gt;}&lt;BR /&gt;});.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code works for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I have another question here, how to call dynamic services like "setProperties" using the same procedure?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Janakiraman P&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 06:54:53 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/631795#M39982</guid>
      <dc:creator>Janakiraman-P</dc:creator>
      <dc:date>2019-10-17T06:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to get proper response in ajax call, returning HTML response instead json.</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/631961#M40002</link>
      <description>&lt;P&gt;Hello Janakiraman,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad to hear you were able to resolve this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With respect to your other query regarding a dynamic service like setProperties can you give me an example of where this service would appear?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was able find some good examples using REST with SetPropertyValues if this is similar to&amp;nbsp; what you are looking for:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.ptc.com/t5/ThingWorx-Developers/Set-User-Extensions-properties-via-REST-API/m-p/528235#M21942" target="_self"&gt;Example 1&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.ptc.com/t5/ThingWorx-Developers/Add-data-to-an-InfoTable-Data-Shape-using-REST/m-p/508549" target="_self"&gt;Example 2&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Tyler Misner&lt;/P&gt;
&lt;P&gt;ThingWorx Technical Support Engineer&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 15:42:20 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/631961#M40002</guid>
      <dc:creator>tmisner</dc:creator>
      <dc:date>2019-10-17T15:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to get proper response in ajax call, returning HTML response instead json.</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/633603#M40213</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/300450"&gt;@Janakiraman-P&lt;/a&gt;.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;If one of the previous responses allowed you to find a solution to your problem, please mark the appropriate one as the Accepted Solution for the benefit of others on the community.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Regards.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;--Sharon&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 21:13:01 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/Unable-to-get-proper-response-in-ajax-call-returning-HTML/m-p/633603#M40213</guid>
      <dc:creator>slangley</dc:creator>
      <dc:date>2019-10-28T21:13:01Z</dc:date>
    </item>
  </channel>
</rss>

