weixin_33743703 2015-10-04 00:29 采纳率: 0%
浏览 44

新手jquery / ajax:为什么会出错?

I've made this simple html page but get "error" alert popup when calling example.com. Why?

<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js"></script>
        <script type="text/javascript">
            function errorAlert(e, jqxhr) {
                alert("Your request was not successful: " + jqxhr);
            }
            function processData() {
                alert("success")
            }
            $.ajax(
            {
                type: "post",
                url: "http://example.com",
                success: processData,
                error: errorAlert
            }); //end of $.ajax
            </script>
    </body>
</html>

I'm running on Chrome 45.0...

  • 写回答

1条回答 默认 最新

  • ?Briella 2015-10-04 00:36
    关注

    You can see different types of JavaScript errors in the developer console (F12 in Google Chrome). You will see: "XMLHttpRequest cannot load http://example.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."

    Take a look here for a detailed explanation: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '...' is therefore not allowed access

    But basically, the host you send the request to must match the origin, or explicitly allow foreign hosts.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!