#1 2015-10-22 01:59:14

brambs
Member
Registered: 2015-10-22
Posts: 1

HTML Compiler - It's possible to made AJAX requests?

Hi,

I'm trying to load the contents of an html file to a <div> in my index using the jQuery .load() method and it doesn't show any html inside the <div>. Is this possible to do with HTML Compiler?

Offline

#2 2015-10-22 06:46:31

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: HTML Compiler - It's possible to made AJAX requests?

Hello brambs,

Thanks for your interest in HTML Compiler. The problem with AJAX and local files is the Internet Explorer custom protocol behind HTML Compiler. Such protocol doesn't allow us to use AJAX for local files. But, on the other hand, such protocol is fundamental in the program, since they allow us to assert that any file included in HTML Compiler is extracted to the user computer.

A possible solution is to use a remote file with "jQuery.load" or other AJAX technique, since remote files are not served by the HTML Compiler custom protocol, we can do something like that without problems, only assert that "CORS" is enabled for that file in our server. Other possible solution is to implement some kind of "read file" in HTML Compiler external Javascript functions, but this is not currently available.

Here is a sample of "index.html" which use "jQuery.load":

<!DOCTYPE html>
<html lang="en" dir="ltr">
 <head>   
  <meta charset="utf-8" />
  <meta name="viewport" 
   content="width=device-width, initial-scale=1" />
  <title>HTML Compiler remote AJAX sample</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script>
  $(document).ready(function(){
    $("button").click(function(){
      $("#div1").load("http://davidesperalta.com/Humm/Sites/Main/Views/Data/HtmlCompiler/Samples/Ajax/ajax.php");
    });
  });
  </script>
 </head>
 <body>
  <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
  <button>Get External Content</button>
 </body>
</html>

And below we can see the contents of the "ajax.php" file used above:

<?php

// Enable CORS (http://enable-cors.org/server_php.html)
header('Access-Control-Allow-Origin: *');

echo 'Hello from a remote AJAX file!';

exit;

If you have any other question or doubt, please, don't hesitate to post it here.

Offline

#3 2016-10-23 23:09:53

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: HTML Compiler - It's possible to made AJAX requests?

Hello to all,

Just to update this thread: the current release of HTML Compiler allows us to read and write text files from our applications. Take a look at the Javascript external stuff that HTML Compiler offer and also take a look to the included "ReadFile" and "WriteFile" applications samples.

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.