sending array using XML code to action sequence

Using XMLHttpRequest() to configure entire ToolBook pages.

sending array using XML code to action sequence

Postby John Robin Dove » Tue Jan 07, 2020 7:50 am

Hi Clifton,
Happy New Year! :)

Thanks once again for the brilliant XML system. If I had used it from the start maybe my project would have been finished years ago!

Here is my latest problem.

I store data in an array called PDetails. When the user has finished creating an exercise, the data in PDetails is transferred to a text file. PDetails contains 10 lines of comma separated values.
I use 3 files IT.tbk, Ex.tbk and IT1.tbk so 3 different windows in this part of my program: 'IT' (main window) and 'Ex' and 'IT1' which are loaded using pgGotoURL. 'IT' and 'IT1' use action sequences as I made them some time ago. 'Ex' uses code loaded by an XMl file. They all have a PDetails array and when PDetails is modified in one window the other 2 must have their PDetails array modified simultaneously. I have no problem transferring the PDetails array from IT to IT1 (both use action sequences and TB global variables) but I have not succeeded in transferring the PDetails array in 'Ex' which is stored as a 'make object property' to the other 2 windows. Here is part of the code:

<make id="sharedActions" type="div" level="0" dims="-50,-50,20,20" class="" refObj="sysbootstrap" autoAlign="" replace="">
<style>
{ "display" : "none" }
</style>
etc ...

//this.currentLine = tbfunction_pgSplitToArray(sharedActions2.PDetails[currentNo],",", true);!!

<function name="modifyCurrentLine" event="" params="itemNo,item">
<![CDATA[
this.currentLine[itemNo] = item;
var newLine = this.currentLine [1] + "," + this.currentLine [2] + "," + this.currentLine [3] + "," + this.currentLine [4] + ","
+ this.currentLine [5] + "," + this.currentLine [6] + "," + this.currentLine [7] + "," + this.currentLine [8] + "," + this.currentLine [9];
sharedActions2.PDetails[this.docNo] = newLine;
tbfunction_pgExecuteRemote("main", "tbfunction_pgTBObjSet" ["ML4", "user", sharedActions2.PDetails]);
]]>
</function>
</make>


The ML4 field in the main window does not seem to receive the sharedActions2.PDetails array. Can you suggest why please?

Thanks for your time.
John

UPDATE Just spotted the error! no comma after "tbfunction_pgTBObjSet" In the meantime I've been sending only the variable newLine to update the array in IT as the complete array did not need to be updated. So I still don't know if there was a real problem or not.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: sending array using XML code to action sequence

Postby Clifton » Tue Jan 07, 2020 5:01 pm

Glad you found the problem with the comma.
    tbfunction_pgExecuteRemote("main", "tbfunction_pgTBObjSet" ["ML4", "user", sharedActions2.PDetails]);
    ... should be ...
    tbfunction_pgExecuteRemote("main", "tbfunction_pgTBObjSet", ["ML4", "user", sharedActions2.PDetails]);

I do very little coding in the Actions Editor anymore as the XML features allow me to export once and experiment by just modifying the XML files in the export until I achieve the effects I'm looking for.

Just a little note when sending data to a web servers:
    It can be very handy to send your complex server data in JSON format.
    Here is an example:
        var serverData = { time : 120, user : 'Clifton', exercise : 4, responses : [ 1, 4, 2, 4, 3, 1] }; //Complex JavaScript object
    serverData = JSON.stringify( serverData );
    var params = [ "data=" + serverData ];
    tbfunction_XMLHttpRequest( "POST", [url], params, this.name );


    In the above example, the following string will be sent to the server:
    {"time":120,"user":"Clifton","exercise":4,"responses":[1,4,2,4,3,1]}


    When the server receives the data, simply decode with the following PHP function, like this:
    $data = json_decode( $_POST["data"] ); //$data is now a PHP associative array very similar to the original JavaScript object


    You can use JSON.stringify() and JSON.parse() when sending data at the client level also. Plus you can store the JSON data in the session storage of the browser when and if needed. Our new https://LearnToType.Today software uses these techniques a lot to manipulate student typing exercises, track their progress and print their certificates.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: sending array using XML code to action sequence

Postby John Robin Dove » Wed Jan 08, 2020 6:50 am

Thanks for all this useful info.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am


Return to XML Configurations – Plugin Examples

Who is online

Users browsing this forum: No registered users and 2 guests

cron