Results 1 to 10 of 10
  1. #1
    Senior Member
    Join Date
    Oct 2009
    Location
    cbba
    Posts
    33

    how to send a LS server message to a javascript function like a json parameter

    hi all,
    now i'm working with javascript code, i reed the Web Client Dev and i see the jsdoc.
    i can't find a way to send the message from my javaadapter to a javascript function.

    i created my java adapter, this create a String with a json, something like this
    String sMessage = "{field1:'value1',field2:'value2',....}";

    how can i do to pass this String to a javascript function?? and then, how can i run this javascript function with this parameter?? depending of the values i have to hide or show some areas of my web site.

    thanks for your help.

  2. #2
    Senior Member
    Join Date
    Oct 2009
    Location
    cbba
    Posts
    33
    well, i try to create a NonVisualTable with a group and schema and the subscription mode is COMMAND, when i try to run this an alert show me with this message

    1: 18:18:46,590 ER addTable Key position is not set correctly for a COMMAND mode subscription. Please specify a field that represents the Key
    when i change the mode to MERGE this work fine.

    i'm not sure about the subscription mode operation, i read the document General Concepts, and not finish to understand, can you explain me??

    about the obtain the message with a java script function, it's done
    the problem is how to conver my string to json.
    is there a way to pass a json parameter instead a string??

    regards

  3. #3
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    975
    Unfortunately, no facility is provided for manipulating json data on the client side;
    the update event handler of your NonVisualTable should use the received string and directly use eval or any more sophisticated technique available.

    About subscription modes, they allow for managing a sequence of updates in different ways.
    The name of COMMAND mode may be misleading;
    anyway, it is not aimed at pushing javascript code, but rather at pushing list contents and their changes (through list manipulation "commands").
    At this stage, you can concentrate on MERGE mode and ignore other subscription modes.

  4. #4
    Senior Member
    Join Date
    Oct 2009
    Location
    cbba
    Posts
    33
    thanks for your help, i work with MERGE mode.
    i try to work with a string, the problem is i need to pass a lot of data and analyze this information and analyze this information. i see the way to do this.

    regards.

  5. #5
    Senior Member
    Join Date
    Oct 2009
    Location
    cbba
    Posts
    33
    hi again,

    i have a new and strange error

    well, I managed to create an application in the following path
    www.mydomain.com/myapp/lsAlarms.php --> master push-page
    everything works in this environment

    i try to change this index.php to
    eco.mydomain.com/myapp/lsAlarms.php

    when i try to run this second a javascript alert show me this message

    1: 18:38:21,223 ER bind Unable to find the Engine. Retrying. If the problem persists, please check your configuration.
    i don't now why this happends :S the code is the same. i only change www.mydomain.com to eco.mydomain.com

    do you have any idea why this happends??

  6. #6
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784
    Please paste here the code you use to configure your PushPage instance.

  7. #7
    Senior Member
    Join Date
    Oct 2009
    Location
    cbba
    Posts
    33
    here is my push code

    HTML Code:
    <html>
    
    <head>
    	<title>Hello World with Lightstreamer</title>
    	<script language="JavaScript" src="LS/lscommons.js"></script>
    	<script language="JavaScript" src="LS/lspushpage.js"></script>
    </head>
    
    <script>
    	var page = new PushPage();
    	page.context.setDomain("<?=$gsDomain?>"); // dominio.com
    	page.onEngineCreation = function(engine) {
    		engine.connection.setLSHost("<?=$gsLSHost?>"); // push.dominio.com
    		engine.connection.setLSPort(<?=$gsLSPort?>);
    		engine.connection.setAdapterName("ECONOTIFICATIONS");
    		engine.changeStatus("STREAMING");
    	}
    	page.bind();
    	page.createEngine("EcoNotificationsApp", "LS", "SHARE_SESSION");
    	
    	var group = ["<?=$sItemName?>"];
    	var schema = ["message","timestamp"];
    	var pushtable = new NonVisualTable(group, schema, "MERGE");
    	pushtable.setCommandLogic(true);
    	pushtable.setDataAdapter("EcoNotifications");
    	pushtable.setSnapshotRequired(true);
    	pushtable.onItemUpdate = function (itemPos, updateInfo, itemName) {
    		var sMsg = updateInfo.getNewValue("message");
    		var sDate = updateInfo.getNewValue("timestamp")
    		if(sMsg!=null){
    			var objDivAlarm = document.getElementById("divAlarm");
    			objDivAlarm.innerHTML = sMsg + "<br>" + sDate;
    		}
    	};
    	pushtable.onStart = function() {
    		
    	};
    	
    	/*var pushtable = new OverwriteTable(null, null, "MERGE");*/
    	page.addTable(pushtable, "hellotable");
    </script>
    
    <body>
    
    <div id="divAlarm">Empty...</div>
    
    </body>
    </html>

  8. #8
    Senior Member
    Join Date
    Oct 2009
    Location
    cbba
    Posts
    33
    i think i identified the problem, i'm not sure if this is a bug or not.

    the problem occurs when i put the "LS" folder (with JS libraries of Lightstreamer) into a "lib" folder. something like this:
    Code:
    myapp/
    myapp/lib/LS/... --> here is the JS library
    myapp/lsAlarms.php
    in lsAlarms.php add the path in the src
    HTML Code:
    <script language="JavaScript" src="lib/LS/lscommons.js"></script>
    <script language="JavaScript" src="lib/LS/lspushpage.js"></script>

    when i move the "LS lib" to the same level to lsAlarms.php and lib, almost everything works fine (I'll open another post to see to solve another problem). something like this:
    Code:
    myapp/
    myapp/lib/
    myapp/LS/... --> here is the JS library
    myapp/lsAlarms.php
    in lsAlarms.php add the path in the src
    HTML Code:
    <script language="JavaScript" src="LS/lscommons.js"></script>
    <script language="JavaScript" src="LS/lspushpage.js"></script>

    i don't understand why this happends, maybe it's a bug. if you solve this, please let me know.

  9. #9
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784
    hi,

    if you move the libraries you must update, besides the <script> tags, the createEngine call that needs to know where are the libraries located.
    So you can put the LS folder under lib but your createEngine must look like this:

  10. #10
    Senior Member
    Join Date
    Oct 2009
    Location
    cbba
    Posts
    33
    thank you very much, i read that part, but i had not entirely clear, thanks for your help, now works.

    regards.

 

 

Similar Threads

  1. Don't send message when refresh the browser
    By naitsir in forum Client APIs
    Replies: 7
    Last Post: October 2nd, 2012, 11:36 AM
  2. How to send message to each client?
    By hungtt in forum Adapter APIs
    Replies: 7
    Last Post: December 30th, 2010, 04:42 AM
  3. Replies: 6
    Last Post: December 7th, 2010, 10:26 AM
  4. Replies: 1
    Last Post: January 18th, 2010, 04:27 PM
  5. How to send params from client to server
    By kanibal210 in forum Client APIs
    Replies: 1
    Last Post: September 30th, 2009, 09:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 10:33 AM.