Sinatra jQuery GET request always results in an error

I use Sinatra to host a simple service. This is all my application:

require 'sinatra'

get '/hello' do
  'Hello world!'
end

Then I have one html file in my directory ./publicthat is trying to execute a GET request in my service:

<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("a").click(function(event) {
                $.get("/hello", function() { alert("first success"); })
                        .success(function() { alert("second success"); })
                        .error(function(jqXHR) { alert("error: " + jqXHR); });
            })
        });
    </script>
</head>
<body>
<a href="">Link</a>
</body>
</html>

When I click on the link in my HTML page, in my journal log, I see the following:

0: 0: 0: 0: 0: 0: 0: 1% 0 - - [16 / Feb / 2011 10:37:42] "GET / hello HTTP / 1.1" 200 12 0.0030
localhost - - [16 / Feb / 2011: 10: 37: 42 CST] "GET / hello HTTP / 1.1" 200 12
Referer → / hello

Which seems good, but no matter how I try to change the settings, I can only get the error callback - never succeed.

:
1) ?
2) ? , , , .

!

+3
2

, return false;, . Firebug uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.getAllResponseHeaders]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js :: anonymous :: line 16" data: no].

<a href="">Link</a> <a>Link</a>, ( , ). , return false; $("a").click, .

+2
Error: uncaught exception: 
[Exception... "prompt aborted by user"  nsresult: "0x80040111 
(NS_ERROR_NOT_AVAILABLE)"  location: 
"JS frame :: resource:///components/nsPrompter.js :: openTabPrompt :: line 457"  data: no]

, onclick, live href url, .

+1

Source: https://habr.com/ru/post/1792584/


All Articles