简体   繁体   English

“资源被解释为脚本,但以MIME类型text / html传输”响应

[英]'Resource interpreted as Script but transferred with MIME type text/html' response

I have an ajax call to a PHP (on a different domain) login-script, which looks as the following: 我有一个Ajax调用PHP(在另一个域上)登录脚本,该脚本如下所示:

var request = $.ajax({
        crossDomain: true,
        url: "http://www.domain.com/PHP/fct.login.php",
        type: "POST",
        data: $('#loginForm').serialize(),
        dataType: "jsonp",
        contentType: "application/json; charset=utf-8",
    });

And in my PHP script I have following: 在我的PHP脚本中,我有以下内容:

<?php
header('Content-Type: text/javascript');
echo $_GET['callback'] . '(' . "{'status' : '1'}" . "{'text' : 'ok'}" . "{'userid' : $member['user_id']}" . ')';
?>

But it doesn't work. 但这是行不通的。 In my console I just get a Resource interpreted as Script but transferred with MIME type text/html message... 在我的控制台中,我只是将Resource interpreted as Script but transferred with MIME type text/html消息进行了Resource interpreted as Script but transferred with MIME type text/html ...

EDIT : I updated my response as 'Felix Kling' said, but now I'm getting a parse error. 编辑 :我更新了我的回答,如“费利克斯·克林(Felix Kling)”所说,但现在我遇到了解析错误。

My updated response looks like: 我更新后的回复如下:

echo $_GET['callback'] . "({status : 1},{text : 'ok'},{userid : ".$member['user_id']."})";

And the error looks like: 错误看起来像:

Error: Parse error on line 1:
{status : 1},{text :
-^
Expecting 'STRING', '}'

EDIT 2 : Never mind, it works now (with the updated response). 编辑2 :没关系,它现在可以使用(更新后的响应)。 I just got the parse error when I had a direct look at the php script via the browser (without ajax call, etc.). 当我通过浏览器直接查看php脚本时(没有ajax调用等),我只是遇到了parse error

The JS code you generate is incorrect. 您生成的JS代码不正确。 It will look like 看起来像

callbackName({'status': '1'}{'text' : 'ok})

but you cannot put to object literals after each other. 但是您不能将对象字面量放在后面。

Either you have to generate one literal: 您要么生成一个文字:

callback({status: 1, text: 'ok'})

or multiple arguments, separated by commas: 或多个参数,以逗号分隔:

callback({status: 1}, {text: 'ok'})

although I think jQuery expects only one argument to be passed to the callback. 尽管我认为jQuery期望仅将一个参数传递给回调。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 资源被解释为脚本,但以MIME类型text / html javascript传输 - Resource interpreted as Script but transferred with MIME type text/html javascript Rails&Heroku:资源被解释为脚本,但以MIME类型text / html传输 - Rails & Heroku: Resource interpreted as Script but transferred with MIME type text/html 资源被解释为脚本,但在单个站点上以MIME类型text / html传输 - Resource interpreted as Script but transferred with MIME type text/html on individual site “资源被解释为脚本,但使用MIME类型text / html进行传输。” - “Resource interpreted as script but transferred with MIME type text/html.” Chrome错误-资源被解释为脚本,但以MIME类型的文本/纯文本传输 - Chrome Error - Resource interpreted as Script but transferred with MIME type text/plain ajax错误:资源被解释为脚本,但以MIME类型text / json传输: - ajax error: Resource interpreted as Script but transferred with MIME type text/json: js警告:资源被解释为脚本,但以MIME类型text / plain传输 - js warning: Resource interpreted as Script but transferred with MIME type text/plain 资源被解释为脚本,但以MIME类型text / x-js传输 - Resource interpreted as Script but transferred with MIME type text/x-js 资源解释为脚本,但使用MIME类型text / plain传输 - 用于本地文件 - Resource interpreted as Script but transferred with MIME type text/plain - for local file 资源解释为Font但在Opencart中使用MIME类型text / html进行传输 - Resource interpreted as Font but transferred with MIME type text/html in Opencart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM