Why does return falsely stop the warning?

Why does it return falsestop work alert()and how can I get around this? If I delete it, a warning will appear and then it will load the page the tag points to <a>.

<script type="text/javascript">
    $("document").ready(function(){
        $("a").click(function(){
            if(!$(this).is('static')){
                var href = $(this).attr('href');
                $.getJSON(href, function(data) {
                    alert('hi');
                });
            }
            return false;
        });
    });
</script>
+3
source share
3 answers

I assume that badly formed JSON is sent to the client, which will prevent the callback from starting. The manual says:

If there is a syntax error in the JSON file, the request is usually not executed silently. Avoid frequent manual editing of JSON data for this reason.

Can you show us the JSON snapshot that the server generates?

+4
source

Update message!

, $.ajax, $.getJSON.

$("document").ready(function(){
    $("a").click(function(event){
        if(!$(this).is('static')){
            var href = $(this).attr('href');
            $.ajax({
              url: href,
              dataType: 'text',
              success: function(data) {
                  alert("hi");
              }
            });

        }
        return false;
    });
});

JSON , . json.html:

{ "firstName" : "John",
                "lastName"  : "Doe",
                "age"       : 23 }

, HTML JSON, - , , , :

$("document").ready(function(){
    $("a").click(function(event){
        if(!$(this).is('static')){
            var href = $(this).attr('href');
            $.ajax({
              url: href,
              dataType: 'text',
              success: function(data) {
                  alert("hi");
              },
              error: function() {
                alert("NO!!!!");
              }
            });

        }
        return false;
    });
});

, , , , $.get, $.getJSON. , :

<script type="text/javascript">
    $("document").ready(function(){
        $("a").click(function(){
            if(!$(this).is('static')){
                var href = $(this).attr('href');
                $.get(href, function(data) {
                    alert('hi');
                });
            }
            return false;
        });
    });
</script>
+3

, , Firefox 3 Chrome, get, getJSON.

IE8 - ( , IE7). ; getJSON . JSON, , IE?

0

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


All Articles