Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .getJSON方法在Firefox和chrome中不起作用。在IE中运行良好_C#_Jquery_Json_Visual Studio 2012 - Fatal编程技术网

C# .getJSON方法在Firefox和chrome中不起作用。在IE中运行良好

C# .getJSON方法在Firefox和chrome中不起作用。在IE中运行良好,c#,jquery,json,visual-studio-2012,C#,Jquery,Json,Visual Studio 2012,我有一个.getJSON方法。它在IE浏览器中运行良好,在firefox和Chrome等其他浏览器中不起作用。这是密码 <script src="Themes/Js/jquery_v_1.4.js"></script> <script type="text/javascript"> var url; $(document).ready(function () { url = "http://192.168

我有一个.getJSON方法。它在IE浏览器中运行良好,在firefox和Chrome等其他浏览器中不起作用。这是密码

<script src="Themes/Js/jquery_v_1.4.js"></script>
<script type="text/javascript">
        var url;
        $(document).ready(function () {
            url = "http://192.168.0.171:8080/api/account";
            $('#btnSubmit').click(function (e) {
                debugger;
                $.getJSON(url, function callback(data, status, jqXHR) {
                    debugger;
                    $('#<%= ddlList.ClientID %>').append('<p>Name : ' + jqXHR.responseText + '</p>');
                });
            });
        });
</script>

var-url;
$(文档).ready(函数(){
url=”http://192.168.0.171:8080/api/account";
$('#btnsupmit')。单击(函数(e){
调试器;
$.getJSON(url,函数回调(数据,状态,jqXHR){
调试器;
$('#')。追加('名称:'+jqXHR.responseText+'

'); }); }); });
在Firefox和chrome中,控件不在函数回调中。
请看一看并给我建议。

我认为
调试器
语句可能仅在IE中受支持。请尝试将其删除

如果您的代码在IE中正常工作,但在Chrome中不正常工作,则可以尝试任何可用的虚拟服务器,如Python Server

按照步骤操作

1.在相应的文件夹中运行命令(在Linux中)

python-msimplehttpserver

2.打开Chrome浏览器并浏览localhost:8000/filename

现在可以正常工作了

我在Web api Global.asax中添加了以下代码

protected void Application_BeginRequest(object sender, EventArgs e)
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
        if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
        {
            HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
            HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
            HttpContext.Current.Response.End();
        }
    }

感谢大家的支持。

为什么jQuery的版本这么旧?什么“不起作用”?控制台中是否报告了错误?如果没有,是否发送网络流量?它是否按预期返回?哪个版本的jquery适合于此。请建议使用最新的jquery版本。jquery版本的使用没有限制。但最好是使用最新版本,因为有更多的功能可用。移动到最新版本时要小心,您使用的某些方法可能已被弃用。已删除调试器。但是没有用。还是同一个问题必须确定。你把它们都拿走了,对吧?在chrome/FF中调试时是否出现错误?是的,我删除了调试器;但我在chrome/FF中没有收到任何错误消息。控件未进入函数回调(数据、状态、jqXHR)的内部