Forum > Networking and Web Programming

Ajax and Http server application lazarus

(1/1)

xinyiman:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---     AResponse.ContentType := 'text/html;charset=utf-8';     AResponse.Content:='hello world';     Handled := True; 
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---<html><script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script type="text/javascript">function Read(){            $.ajax({            url: "http://127.0.0.1:8080/gettext.html",            contentType: "application/x-www-form-urlencoded;charset=utf-8",            success: function (response)             {                           alert(response);                                },            error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + errortext); },            async: true        }); }</script><body> <button onclick="Read()">-Premi-</button> </body></html> 

Phil:

--- Quote from: xinyiman on August 13, 2017, 05:22:59 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.

--- End quote ---

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?

Navigation

[0] Message Index

Go to full version