weixin_33716557 2018-09-26 15:51 采纳率: 0%
浏览 24

C服务器-AJAX响应标头

I have a small C server that has always the same respond:

"HTTP/1.1 200 OK Server: CServer Access-Control-Allow-Headers: x-requested-with Content-Type: text/html Content-Length: 14 Connection: close <h1>Done</h1> ";

I can now call the webserver with my Browser and get the expected result, however, the same thing does not work with AJAX.

The Request is being sent and I also get the response back with the Response-Payload:

Done

But the error function is being executed: alert("An error occured: " + xhr.status + " " + xhr.statusText); with xhr.status = 0 and xhr.statusText = error, which is not really helping me.

Is my response-package incorrect? What do I need to change?

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#button").click(function(){
        $.ajax({
            type: "GET",
            dataType : 'html',
            url: "http://localhost:8080/demotest.txt", 
            success: function(result){
                $("#div1").html(result);
            },
            error: function(xhr){
                alert("An error occured: " + xhr.status + " " + xhr.statusText);
                console.log(xhr);
            }
        });
    });
});
</script>
</head>
<body>
<div id="div1"><h2>Before</h2></div>
<button id="button">Get Content</button>
</body>
</html>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分