Jump to content

Recommended Posts

Posted

I was using a unihtmlFrame,which hold a jquery tree.

 

Now ,I want to do some query after user click some node, The question is as the title.

 

source code:

 

     function onClick(event, treeId, treeNode) {
        if (treeNode.level == 1 )
        {
   
         MainForm.UniEdit1.setValue(treeNode.SQL);   //can be see

         MainForm.DoQuery(treeNode.SQL);
        
         
        ajaxRequest(MainForm.UniHTMLFrame1,
           'Click',
           ['sql='+treeNode.SQL]);
        }
      }
    
      
  

 

at present ,none of the direct call or the ajax call can be execute.

 

Thanks for any help or suggestion!

Posted

at present ,none of the direct call or the ajax call can be execute.

 

What is in treeNode.SQL? If it contains spaces, quotes or other non-alphanumeric chars, that code might fail

         ajaxRequest(MainForm.UniHTMLFrame1,
           'Click',
           ['sql='+treeNode.SQL]);
        }

Farshad should know more on this, I didn't dig into ajaxRequest inners myself. Try this for example

         ajaxRequest(MainForm.UniHTMLFrame1,
           'Click',
           ['sql='+encodeURIComponent(treeNode.SQL)]);
        }

Even better, refer to items by their index, not value. I suppose you build a tree inside UniGui on server side, so you should have all items available and just need an index of a clicked item. I think zTree (or what was that component you've been using) should have a method to get an index by value.

  • Administrators
Posted

I was using a unihtmlFrame,which hold a jquery tree.

 

Now ,I want to do some query after user click some node, The question is as the title.

 

source code:

 

     function onClick(event, treeId, treeNode) {
    	if (treeNode.level == 1 )
    	{
   
         MainForm.UniEdit1.setValue(treeNode.SQL);   //can be see

         MainForm.DoQuery(treeNode.SQL);
    	
         
    	ajaxRequest(MainForm.UniHTMLFrame1,
           'Click',
           ['sql='+treeNode.SQL]);
    	}
  	}
	
  	
  

 

at present ,none of the direct call or the ajax call can be execute.

 

Thanks for any help or suggestion!

 

Where do you handle ajax calls on server side?

Posted

Where do you handle ajax calls on server side?

 

Thanks for both of your's instant response.

 

I was build a tree inherited by ztree on client side.the .SQL property was i extend by ztree's node,have nothing to do with this topic.

 

what I want to do was when user click some of the node, we should take some action and fetch data from server to show in a dbgrid.

 

the code show on the top was that, I have just test two different way,on call a query directly in javas cript and anther is test for using a ajax action define response in unguiHTMLFrame ajax handle event. but none of them success yet.

Posted

I was build a tree inherited by ztree on client side.the .SQL property was i extend by ztree's node,have nothing to do with this topic.

Actually it HAS to do with this topic since you are trying to pass it's content to UniGui app via ajaxRequest, and because you can't perform queries directly in javascript.

So I repeat my question - what does SQL property contain?

Posted

Actually it HAS to do with this topic since you are trying to pass it's content to UniGui app via ajaxRequest, and because you can't perform queries directly in javascript.

So I repeat my question - what does SQL property contain?

 

 

SQL property is just a node of ztree's property defined by myself.

Posted

Where and how it is declared?

 

Thanks for Farshad for so instant replay.

 

in fact,all i want to do is declared as the title: How we do a sql query in a java script

 

 

at first,I defined a UniMainModule.DoQuery procedure as bellow:

procedure TUniMainModule.DoQuery(sSQL:string;aDataSet:TDataSet=nil;sLog:string='');
begin
 if aDataSet=nil then
    aDataSet:=qySuper;
 //todo:Only think TADOQuery now.
 with aDataSet as TADOQuery do
   begin
     Close;
     SQL.Text:=sSQL;
     Open;
     //todo Save Log
   end;
end;

 

In UI, I defined a click event in pascal,It works fine:

procedure TMainForm.UniBitBtn2Click(Sender: TObject);
begin
   DoQuery(UniEdit1.Text);
end;

 

All I want to do is call it from JS,so I defined a simple extEvents click as below .

 

function OnClick(sender, e)
{
 alert( MainForm.UniEdit1.getValue( )+'asdf');            //fine
 UniMainModule.DoQuery( MainForm.UniEdit1.getValue( ));   //fail, Here is the question : I debug and and find it not work at all!
 alert(  MainForm.UniEdit1.getValue( ));                  //fail
}

 

I guess the reason is the DoQuery has be rename to some thing else,since i debug in the html's source code and find no that declaration named DoQuery at all!

 

So my question may be simplified as "HOW TO CALL A DELPHI'S PROCEDURE FROM JS"

 

Thanks for Farshad's help again!

Posted

I am so sorry for have waste both of u so many time, All can be do in a jaxevent your have given!

 

Thanks also and I will try my best to do some contribution for unigui.

  • Administrators
Posted

You can't call a Delphi method from JavaScript.

 

On client side:

     	ajaxRequest(MainForm.UniHTMLFrame1,
           'Click',
           ['sql='+encodeURIComponent(treeNode.SQL)]);
    	}

 

On serverside:

 

procedure TMainForm.UniHTMLFrame1AjaxEvent(Sender: TComponent;
 EventName: string; Params: TStrings);
var S : string;
begin
 if SameText(EventName, 'click') then
 begin
S:=Params.Values['sql'];
DoQuery(S);
 end;
end;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...