Ajax call not working in IE8

I read a few posts about this and made some changes to my code, but no luck.

Can anyone look into this to see what is happening here? Or maybe another way to do what I need (get a city, specify a zip code using ziptastic)

Code works fine in Chrome ( http://jsfiddle.net/7VtHc/117/)

HTML

<asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox>        
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox> 
<asp:TextBox ID="txtState" runat="server"></asp:TextBox> 

script

<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $("input[id$='txtZipCode']").keyup(function () {
            var el = $(this);

            if (el.val().length === 5) {
                $.ajax({
                    url: "http://zip.getziptastic.com/v2/US/" + el.val(),
                    cache: false,
                    dataType: "json",
                    type: "GET",
                    success: function (result, success) {
                        $("input[id$='txtCity']").val(result.city);
                        $("input[id$='txtState']").val(result.state);
                    }
                });
            }
        });
    });
</script>

Thank,

+4
source share
4 answers

, IE8 Cross Resource Resource Sharing (CORS) XHR, - ajax- XHR jQuery $.ajax.

IE8 Microsoft - XHR CORS XHR, XDomainRequest, IE8. .

- , , .

+6

" " ajax. jQuery.support.cors = true;

IE .

    <html>
    <head>
    <script type='text/javascript' src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
          <script>
    $(document).ready(function() {
        jQuery.support.cors = true;
        $("#zip").keyup(function() {
            var el = $(this);

            if (el.val().length === 5) {
               $.ajax({
                    url: "http://zip.getziptastic.com/v2/US/" + el.val(),
                    cache: false,
                    dataType: "json",
                    type: "GET",
                    success: function(result, success) {
                        $("#city").val(result.city);
                        $("#state").val(result.state);
                    }
                });
            }
        });
    });

    </script>
    </head>
    <body>
        <p>Zip Code: <input type="text" id="zip" /></p>
        <p>City: <input type="text" id="city" /></p>
        <p>State: <input type="text" id="state" /></p>
    </body>
    </html>

:

+9

, IE8, , , , , application/json

PHP

header('Content-Type: application/json');
0

:

<meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1" />
0

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


All Articles