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

The PTC Community email address has changed to Learn more.

Other alternative to xmlhttp


Other alternative to xmlhttp

Hi everyone, 

I have a file.txt that is written with json rules. Into my project I want to access the data of the file like a simply array. 


Is there other way to open this txt file?


My code is the following one: 


var xmlhttp = new XMLHttpRequest(); //apertura del file sequenze
xmlhttp.onreadystatechange = function() {
	if (this.readyState == 4 && this.status == 200) {
		myObj = JSON.parse(this.responseText)
        console.log(myObj.repair_sequence) // repair_sequence è il nome dell'oggetto indicato nel file .txt formattato con grammatica json
      	$scope.updateLabel = function(){   //parameter viene passato quando si seleziona la lingua nei rispettivi pulsanti
        	console.log("----STEP STARTED----")
      		$scope.$on("stepcompleted", function () { //questa chiamata attende il completamento del passo prima di azzerare la stringa "text"
            	console.log("----STEP COMPLETED----")	
				$scope.setWidgetProp( "stepDescription", "text", text)  //step-description è il nome della label in cui di vanno a stampare le indicazioni dei passi 
        	$scope.$on('stepstarted', function() {
         		var currentStep = $[nomeVista].currentStep //nomeVista corrisponde al nome della vista creata nel canvas
         		var repair_selection = $scope.getWidgetProp(nomeVista, 'sequence')
               	if(repair_selection == sequence_1)
        		else if(repair_selection == sequence_2)
          		// stampa descrizione sequenza di manutenzione 
    			// traino[0]: italiano
              	//traino[1]: inglese
          		text =  myObj.repair_sequence[sequence_type].traino[0].description[currentStep-1];
                $scope.setWidgetProp( "stepDescription", "text", text)        






Hi @leonardosella ,

I think the solution in this case is always similar:

- you will try to read the file into session

-you will try to interpret the file.

For example, if we have a json file (because the extension should still point of the content of the file) - txt file could be any thing:


{"button-1":{"class":"button1"},"button-2":{"class":"button1"},"button-3":{"class":"button1"},"3DLabel-1":{"visible":false,"text":"This is PTC Remote Control Model"}



This should be some properties setting for different widgets

Then we have to use some syntax like this

The main frame calling the code which read the file. Here used the event after loading the 2d view



$scope.jsonData={}; //global $scope variable
$scope.Init=function() {
  console.log("$ionicView.afterEnter was called");
$scope.Init();}) //event: when 2d View loaded



Then here the function for loading the file - used the fetch construct:



//this is the function which handle the json data
 console.warn(  JSON.stringify($scope.jsonData))
catch(wrong){    console.warn(wrong);}

//this is the function which read the file
doRead=function (jsonFile){



There is also a sample implementation of the function setMultipleProp - so set the array to widget properties:



//the code will read the complette JSON File and
//assignee it to a jsonData global variable
//func will set mutliple widget properties according JSON
$scope.setMutipleProps  = function(obj){

 Object.keys(obj).forEach(function (item)  {
                for(var prop in obj[item])    {
                           //print the setting for debugging                 
							console.log("==>$scope.view.wdg["+item+"]["+prop+"]="+obj[item][prop] )