Javascript and textfiles


Im busy with a project that uses Ajax and a Digi connect me. In my project i read out textfiles with ajax and send the data to the screen.(already have this working nicely) But now i also want JavaScript to give some data back to the Digi.
(im using net os 7.4) at the moment im kinda stuck with it. Any help will be really nice.

Can i use JavaScript to write data to a text-file on the server of is there is much better way?

already thank for reading this and i hope someone can help me

yours sincerely,


Not 100% certain, but I think you have to emulate a POST operation when using XMLHttpRequest().
This is trickier than it possibly need be using AWS, because you post the data back to mypage_Form_1.htm, for example.
Two suggestions to try:
a) Set up a page containing a textarea to receive the data, and POST data to the textarea; write the file somewhere using code.
b) Set up a form which will accept a file upload, and simulate the upload.

I found this link which might give some ideas

Yes i looked at the post commands for a few days now. I dont understand this in the ajax example also. If i grab the ajax example

	var whereisThecustomer = "";
	var postData;
	var dataType;
	var theLength;

	// set up variables for the POST
	if(whatToPost == "theZipCode")
	    postData = document.getElementById("theZipCode");
		dataType = "theZipCode";
		theLength = "theZipCode".length;

	    //Doing a POST"POST", whereisThecustomer, true);
		// set up requied fields in the header

		request.setRequestHeader('Content-length',theLength + postData.length + 1);

		//We have opened the request
		request.onreadystatechange = function()
		    //ready state change occurred
			if(request.readyState == 4 &&
			    request.status == 200)
                    // if you want to do something on receipt, add code here
        // send out the post
		request.send(dataType + "=" + postData.value);

i dont understand the part what happens after the send command. Where is de data giong in this example? Is it giong to a function just a variable? I my example it seems that it is not working at all. (thx for the first reply steved2)

You’re basically generating data which is what the browser would generate when doing a ‘Submit’. Hence the two lines generating headers.
Variable whereisThecustomer holds the URL which is the target of the POST

first of all thank for the reply again steved2. Your short comment cleared some up for me but the only thing that is still confusing me is the fact that when i press a submit button the browers is making a request and the data is being handled inside de c code of the AJAX_V.c file(the get and set function). But if i am make a request then (like in the ajax example of digi), then they are making a request to the ajax form ,but where is the data being handles inside de c code?? (does is go to some sort of function or variable of something) . Many thank already steved2

your sincerely,


The data is handled exactly as if you had ‘submit’ the form in the normal way.
So for example, function void setThePhoneNumber(char *theValuePtr) is called when the phone number changes.
With Ajax you only send the value(s) that have changed, instead of the complete form, and I’m guessing that AWS handles this, and only calls each ‘set’ function when it has an updated value to pass to it.

I’ve not tried the example, but it rather looks as if the current values are stored in file /FS/RAM0/formsData.txt - and int updateFile(fileFields fieldToUpdate, char * dataToUpdate, int dataLength) puts the data there

if got it working now, many thank for your help steved2.

postData = document.getElementById("theZipCode");

The problem that occurred at the ajax example was that when i got theZipCode by its element id. It didnt really worked correctly because when in the example you wanted to access the value of the item or the lenght something went wrong and it didn’t do anything.

 request.setRequestHeader('Content-length',theLength + postData.length + 1);

       request.send(dataType + "=" + postData.value);

After i worked my way around this it worked perfectly. Again thanks again for explaining it to me and taking the time for it.

(Made the next changes in my example)

 postData = document.ajaxForm.theZipCode.value;
   request.send(dataType + "=" + postData);

instead of

postData = document.getElementById("theZipCode");
   request.send(dataType + "=" + postData.value);

now it works perfect