Jump to content

ajaxRequest and OnAjaxEvent Problem


SertanSoylu

Recommended Posts

Hi,

 

Q1, I have a problem on ajax events that I can't find any source to resolve the problem.

 

I use DevExtreme grid/pivotGrid (for column filter checkbox with data...) in uniHTMLFrame, with ajaxRequest, I need to load data in JSON format.

I can see the XHR data is sent to browser correctly from chromeDeveloperTools, however when I look at result from console, i see only result = "true" and no data displayed in grid.

if I use JSON String directly, no problem...

 

I tried many way to handle the respone but i couldn't handle...

 

Q2, if I use uniHTMLFrame in a Modal Form, devexpress filter column popup appears on mainForm, popup goes out from htmlFrame,

I couldn't find any solution without putting uniHTMLFrame in to main form.

 

What am I doing wrong, thanks.

 

<div class="demo-container">
   <div id="gridContainer"></div>
</div>
<script>
$(function(){
   var GetCustomers = function(e) {
      var deferred = $.Deferred();
      result=ajaxRequest(MainForm.UniHTMLFrame1,e,[]);
      <!-- result=[{"ID":1,"CompanyName":"Premier Buy"}]  THIS IS OK-->
      console.log(result);
      deferred.resolve(result);
      return deferred.promise(); 
   }
 
    $("#gridContainer").dxDataGrid({
        dataSource: GetCustomers('load'),
        columns: ["ID","CompanyName"]
    }).dxDataGrid("instance");
});    
</script>
 
 
procedure TMainForm.UniHTMLFrame1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
var s:string;
begin
  if EventName = 'load' then
  begin
    s:='['+
    '{"ID":1,"CompanyName":"Premier Buy"},'+
    '{"ID":2,"CompanyName":"ElectrixMax"},'+
    '{"ID":3,"CompanyName":"Video Emporium"}+
    ']';
 
    //unisession.JSONDirect(s);
    //unisession.Response := s;
    unisession.SendResponse(s,true);
  end;
end;
 
Platform:
Delphi Tokyo,
uniGui 1.0.0.1424 (licensed)
 
 
 
Link to comment
Share on other sites

Delphi Developer thank you very much, 
 
Actually I want to understand how do you know to send last parameter false in ajaxRequest, because I googled about ajaxRequest,
 
couldn't find any info (Documentation or webSite), this information is more helpful for the possible feature questions :)
 
What do you think about for Q2, this is the second main point for this third party component.
 

Problem is in attached file.

post-6199-0-28654200-1521294698_thumb.jpg

Link to comment
Share on other sites

Sure, please consider attached project, thanks for your consider.

 

Thanks for the testcase, we will check

 

 

Do you have an advise a method for understanding ajaxRequest and parameters...

 

We will try to give you a more detailed description of this JS function

Link to comment
Share on other sites

  • 2 months later...

Hi,  

 

Q. How  to  catch  EventName in MainForm  from  ajaxRequest  in Index.html   

 

     <refer> -  In this test case ,  I will not use  any components , urlFrame  or urlHtmlFrame  but only on MainForm . 

                  -  I wanted catch Events from MainForm only  

     

     1.    MainForm->script        (   load  external index.html  )  

window.location.href="index.html" 

     2.  index.html 

<div class="container">
  <h1>My First Bootstrap Page</h1>
  <p>This is some text.</p> 

  </br>
  <a href="#" class="btn btn-info" role="button"   onclick="call_ajax();"> Call Ajax </a>

</div>

<script>
	$(document).ready(function(){
            say_hello() ;
	});

		function say_hello(){
		    alert(' hi , Unigui Team !!  you are so nice ~ '); 
		}

		function call_ajax(){
		    console.log(' call_ajax ');
		    top.ajaxRequest( top.MainForm.form , 'call_ajax' ,['menu_id=10000'] , false  ); 
			
		}

</script> 

3.  MainForm -> Events ->OnAjaxEvent 

procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
      //0. call_menu  - should get menu_id
      if EventName = 'call_ajax' then  begin
         showMessage(' call ajax from index.html ' + Params.Values['menu_id'] ) ;

      end;
end; 

4. Error ( chrome console.log )

>  index.html:34 Uncaught TypeError: Cannot read property 'form' of undefined 

 

 

<tested result : all same Error >

     1) . top.ajaxRequest( top.MainForm.form , 'call_ajax' ,['menu_id=10000'] , false ); 

     2) . top.ajaxRequest( top.MainForm.window , 'call_ajax' ,['menu_id=10000'] , false ); 

     3) . parent.ajaxRequest( parent.MainForm.form , 'call_ajax' ,['menu_id=10000'] , false ); 

 

 

what am i wrong ?  ( It's works well on using uniURLFrame and HTMLFrame so on ) .

Always thanks for your Team , 

uni_dbfox_test.zip

Link to comment
Share on other sites

Thank you for always  , Delphi Developer and Farshad !!

 

 

 

There is no MainForm object in an index.html.

 

That's it . I do not know how produce it  for MainForm  in index.html .

 

Though you have given us many good components, we have specifically offered to solve my problem as in this test case, such as uniUrlFrame, uniHTMLFrame.

My Goal is to create a Resposive Web (developed for desktop, tablet, and mobile) using Unigui and Bootstrap.

- I have read about it on Desktop/Demo/Http post callbacks . 

  - but I want to solve these problems very flexively . I meant that after build Server , if possible , there are no needs editing any more in server part programming  . 

)

Test case 1. urlFrame's HTML - IOS devices have trouble displaying fast-responding wep apps (right-width cut, especially not in test cases)
Test case 2. UniGUIServerModuleHTTPCommand. - IOS devices have no problems and can display well-designed HTML, but it is not easy to control the Unigui app.

So to solve my problem,

My test case. It is HTML that does not use uniURLFrame to avoid the invisible problem of IOS devices, but you should easily control the Unigui application through MainFormEvent. (such as form.show)

- BTW ,  How can i call a uniForm  after Index.html ?  if there can not be called  ajaxRequest from index,html to MainForm .

Do you have a good idear?
 

Best regards ,

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...