Load text, and put into EditorGadget

Share your advanced knowledge/code with the community.
jamirokwai
Posts: 40
Joined: Fri Sep 25, 2015 12:00 pm

Load text, and put into EditorGadget

Post by jamirokwai »

Hi there,

had some headaches fiddling with loading of text, and applying it to an EditorGadget.
I am posting this for further reference :-)

Code: Select all

Procedure ApplyDemoSnippet ( gadget, content )
  If IsGadget ( gadget ) : SetGadgetText ( gadget, content ) : EndIf
EndProcedure

Procedure LoadTextIntoEditorGadget ()
  ! jQuery.get('data/test.txt', function(data) {
  !   f_applydemosnippet ( 1, data );
  ! }, 'text');
EndProcedure
ApplyDemoSnippet ( 0, "" )

This one needs an EditorGadget number 1.

Cheers
J.
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Load text, and put into EditorGadget

Post by Peter »

Hello jamirokwai,

using HTTPRequest() prevents headaches ;-)

Code: Select all

Procedure HttpGetEvent(Success, Result$, UserData)
 If Success
  SetGadgetText(UserData, Result$)
 Else
  Debug "HTTPRequest(): Error"
 EndIf
EndProcedure

HTTPRequest(#PB_HTTP_Get, "data/test.txt", "", @HttpGetEvent(), 1)
Greetings ... Peter
Post Reply