* * *

Author Topic: Ajax and Http server application lazarus  (Read 355 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 1577
Ajax and Http server application lazarus
« on: August 13, 2017, 05:22:59 pm »
Hi guys, a question.

How ever when I create a "http server application" program with these simple 3 rows in the OnRequest event

Code: Pascal  [Select]
  1.      AResponse.ContentType := 'text/html;charset=utf-8';
  2.      AResponse.Content:='hello world';
  3.      Handled := True;
  4.  

If I launch a url in a browser I see the word 'hello world' correctly, but if I run an ajax call from an html file I can not see the result.

In my opinion I mistake something in the parameterization of the lazarus program. Does anyone know why?

My javascript code:
Code: Text  [Select]
  1. <html>
  2. <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  3. <script type="text/javascript">
  4. function Read()
  5. {
  6.             $.ajax({
  7.             url: "http://127.0.0.1:8080/gettext.html",
  8.             contentType: "application/x-www-form-urlencoded;charset=utf-8",
  9.             success: function (response)
  10.             {          
  11.                 alert(response);                   
  12.             },
  13.             error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + errortext); },
  14.             async: true
  15.         });
  16.  
  17. }
  18. </script>
  19. <body>
  20.  <button onclick="Read()">-Premi-</button>
  21. </body>
  22. </html>
  23.  
Ubuntu and Mint
Lazarus: 1.2.6
FPC: 2.6.4

Phil

  • Hero Member
  • *****
  • Posts: 2305
Re: Ajax and Http server application lazarus
« Reply #1 on: August 13, 2017, 05:27:46 pm »
If I launch a url in a browser I see the word 'hello world' correctly, but if I run an ajax call from an html file I can not see the result.

Check your browser dev tools for error messages. For example, in Firefox open the Browser Console.

Maybe you're hitting the browser restrictions on cross-domain calls?

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus