Skip to main content
 首页 » 编程设计

jquery之ajax发布错误: NETWORK_ERR: XMLHttpRequest Exception 101

2026年07月28日9傻小

我有以下 ajax 帖子:

$.ajax( { 
    type: "POST", 
    url: "http://192.168.7.9/api", 
    dataType: 'json', 
    data: { username: "john.doe", password: "123456", method: "search_samples" }, 
    success: function ( data ) { 
       // Never get here 
    }, 
    error: function ( XMLHttpRequest, textStatus, errorThrown ) { 
        // Always here: if async true, errorThrown has no message 
        // otherwise I se the NETWORK_ERR message 
    } 
} ); 

返回时出现以下错误:NETWORK_ERR:XMLHttpRequest 异常 101。

我已经阅读了很多关于此错误的帖子,大多数建议我将 async 设置为 true。这确实删除了错误消息 - 但它仍然是一个错误,并且我从未获得有效数据。它似乎只是删除了没有帮助的错误消息。

在 fiddler 中,在同一台开发机器上,这完美地工作 - 这是 chrome 问题吗?原产地问题?我的语法有问题吗?

请您参考如下方法:

好的,您似乎遇到了 same origin policy 的问题。按照您的方式,您无法从托管应用程序的服务器之外的其他服务器访问 AJAX 数据。

为此,您必须将 http://192.168.7.9/api 功能移至您的服务器上,或者使用 JSONP 传输数据。 Here是如何执行此操作的示例。