Treat callback response in $.ajax() as JSON

狂风中的少年 提交于 2020-01-06 04:06:24

问题


I have:

<script>
    $('#email').on('blur', function(){
        email = $(tihs).val();
        $.ajax({
            type: "POST",
            url: "ajax.php",
            data: {
                'email': email,
                'job': 'check',
            },
            dataType: "JSON",
            success: function (response) {
                // the response from PHP is smth like:
                // {"status":"failed","reason":"email_not_validated"}
                // now I want to:
                if(response.status == 'success'){

                }else{

                }
            }   
        })
    });
</script>

This seems to work on every browser except IE, why is that?

Am I doing the right thing? the only thing which I need is to access the returned data like response.status and response.reason .

Thanks for helping


回答1:


This is a mentioned IE10 bug that can be fixed by adding

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />

in the <head>. Note in a <head> there should not be another meta tags with X-UA-Compatible as the previous one will be overridden.



来源:https://stackoverflow.com/questions/22007423/treat-callback-response-in-ajax-as-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!