Resource interpreted as Document but transferred with MIME type application/json

在做前后端分离的项目中,当时在做使用easyUI做添加数据的时候,希望后台有返回值给前台接收来记录,可是执行方法之后发现没有返回值。

打开浏览器检查出现警告,如下(这是由于跨域接收返回的json数据问题)
在这里插入图片描述
Resource interpreted as Document but transferred with MIME type application/json
翻译:资源被解释为文档,但使用MIME类型application/json传输

我的解决方法是换一种提交方式:

当时通过$('#ff').form()进行提交:

$("#btn").click(function() {
    $("#ff").form("enableValidation");
    if ($("#ff").form("validate")) {
        $('#ff').form('submit', {
            url : 'http://127.0.0.1:10011/si/service/service/insert',
            onSubmit : function() {
                return true;
            },
            success : function(count) {
                var count = $.parseJSON(count);
                //可以定义为对应消息框
                if (count > 0) {
                    alert(count);
                    alert("添加成功!");
                } else {
                    alert(count);
                    alert("添加失败!");
                }
                parent.$("#win").window("close");
                win.$("#dg").datagrid("reload");
            }
        });
    }
});

换成$.post();方式进行提交,问题解决

$("#btn").click(function() {
	$("#ff").form("enableValidation");
	var url ="http://127.0.0.1:10011/si/service/service/insert";
	var sendData = $("#ff").serialize();//提交form表单数据
	$.post(url, sendData, function (backData, textStatus, ajax) {
		if(textStatus){
		    alert(ajax.responseText);
			alert("添加成功!");
		}else{
			alert("添加失败!");
		}
		parent.$("#win").window("close");
		win.$("#dg").datagrid("reload");
	});
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值