脚本标记中api.php包含文件中的EXTJS错误 [英] EXTJS ERROR in api.php inclusion file in script tag

查看:56
本文介绍了脚本标记中api.php包含文件中的EXTJS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在前端使用sencha Extjs 6.0.2,在后端使用mongodb.但是,每当我尝试使用脚本标记将api.php文件添加到index.html文件中时,它都会引发一些异常.在index.html中,我为api.php文件包含添加以下代码.

i'm using sencha Extjs 6.0.2 in the forntend and mongodb in the backend. But, whenever i try to add api.php file in index.html file using script tag, it throws some exception. In index.html i add the following code for api.php file inclusion.

<script  src="php/api.php"  type="text/javascript"  ></script>

错误是

 Uncaught SyntaxError: Unexpected token <     api.php?_dc=1468481913442:1

我在调试过程中发现的问题是api.php文件被称为html类型.据我所知,php文件应该作为php类型调用,但事实并非如此.有时,当我使用Firebug重新发送文件响应时,它的类型变成了xml.我如何摆脱这个问题?

the problem that i found during debugging is that api.php file is called as html type. As far as i know php file should call as a php type, but it doesn't. some times when i resend the file respone using firebug, it type turned into xml. How can i get rid of this problem?

检查后发现的错误如下:

And the error i found after inspecting is below:

这是我的api.php代码

Here is my api.php code

  <?php
 require('config.php');       
//header('Content-Type: text/javascript');
header("content-type: application/x-javascript"); 

$API = get_extdirect_api('api');

// convert API config to Ext Direct spec

$actions = array();
foreach($API as $aname=>&$a){
 $methods = array();
foreach($a['methods'] as $mname=>&$m){
     if (isset($m['len'])) {
        $md = array(
            'name'=>$mname,
            'len'=>$m['len']
        );
    } else {
        $md = array(
            'name'=>$mname,
            'params'=>$m['params']
        );
    }
    if(isset($m['formHandler']) && $m['formHandler']){
        $md['formHandler'] = true;
    }

    if (isset($m['metadata'])) {
        $md['metadata'] = $m['metadata'];
    }
    $methods[] = $md;
}
$actions[$aname] = $methods;
}

$cfg = array(
'url'=>'php/router.php',
'type'=>'remoting',
'actions'=>$actions
 );
 echo 'var Ext = Ext || {}; Ext.REMOTING_API = ';

 echo json_encode($cfg);
 echo ';';
// document.getElementById("demo").innerHTML = "Hello JavaScript";
 ?>

我尝试将api.php文件类型发送为JS文件. 预先感谢

i try to send the api.php file type as JS file. Thanks in advance

推荐答案

我太新了,不能写评论,所以我只写在这里,我不确定是否有帮助,但是:您正在使用什么来处理php文件?

I am too new to write comments so I'll just write here I'm not sure if it is helpful but: What are you using to process the php file?

在使用sencha cmd提供的Web服务器时,我遇到了类似的问题.这只是一个基本的HTTP网络服务器,不支持php,因此您取回了php代码,而不是该php代码应该产生的javascript.

I had a similar problem while using the web server that the sencha cmd provide. This is just a basic HTTP webserver and doesn't support php so you get back the php code instead of the javascript that the php code is supposed to produce.

这篇关于脚本标记中api.php包含文件中的EXTJS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆