帖子
帖子
用户
博客
课程
显示全部楼层
1
帖子
0
勋章
11
Y币

[云开发] 这里为什么会出现Uncaught ReferenceError: api is not defined的错误...

[复制链接]
发表于 2022-6-15 14:16:51
  1. <a href="" onclick="check()" class="button" style="margin-left: 70px;margin-top: 50px;">登录</a>

  2. <script type="text/javascript" src="../script/api.js"></script>
  3.     <script type="text/javascript">
  4.         apiready = function () {
  5.             var user = api.require('user');
  6.             var model = api.require('model');
  7.    
  8.             model.config({
  9.                 appId: 'A6109982262445',
  10.                 appKey: '',
  11.                 host: 'https://d.apicloud.com'
  12.             })
  13.         }
  14.    
  15.         function check(){
  16.             var password = document.getElementById("password").value;
  17.             var worknumber = document.getElementById("worknumber").value;
  18.             var user = $api.require('user');
  19.             user.login({
  20.                 username: worknumber,
  21.                 password: password
  22.             }, function( ret, err ) {
  23.                 if( ret ){
  24.                     window.location.href = "../index.html"
  25.                     alert( JSON.stringify( ret) );
  26.                 }else{
  27.                     alert( JSON.stringify( err) );
  28.                 }
  29.             });
  30.         }
  31.     </script>
复制代码
这里为什么会出现[color=rgba(204, 204, 204, 0.6)]Uncaught ReferenceError: api is not defined的错误啊,求教
可能调用时机不对,apiready 事件未完成
1
帖子
0
勋章
11
Y币
是调用的时机吗,还是定义的位置错了,全部代码在这
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  6.     <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  7.     <title>登录</title>
  8.     <link rel="stylesheet" type="text/css" href="../css/api.css"/>
  9.     <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  10.     <style>
  11.         .logo{ align-content: center;padding: 40px 20px;margin-top: 0px;}
  12.         .input{ align-items: center;padding: 0 70px;outline-color: black;font-size: 15px;}
  13.         body{ background-image: url("../image/350.jpg");}
  14.     </style>
  15.     <script type="text/javascript" src="../script/api.js"></script>
  16.     <script type="text/javascript">
  17.         apiready = function () {
  18.             var user = api.require('user');
  19.             var model = api.require('model');
  20.    
  21.             model.config({
  22.                 appId: 'A6109982262445',
  23.                 appKey: '',
  24.                 host: 'https://d.apicloud.com'
  25.             })
  26.         }
  27.    
  28.         function check(){
  29.             var password = document.getElementById("password").value;
  30.             var worknumber = document.getElementById("worknumber").value;
  31.             var user = $api.require('user');
  32.             user.login({
  33.                 username: worknumber,
  34.                 password: password
  35.             }, function( ret, err ) {
  36.                 if( ret ){
  37.                     window.location.href = "../index.html"
  38.                     alert( JSON.stringify( ret) );
  39.                 }else{
  40.                     alert( JSON.stringify( err) );
  41.                 }
  42.             });
  43.         }
  44.     </script>
  45. </head>

  46. <body>
  47.     <div class="logo">
  48.         <img src="../icon/logo.png" width="320" height="270" >
  49.     </div>
  50.     <div class="input">
  51.         <form action="">
  52.             工号: <input type="text" id="worknumber" autofocus placeholder="在此处输入工号" style="height: 20px;width: 150px;"><br>
  53.             密码: <input type="text" id="password" autofocus placeholder="在此处输入密码" style="height: 20px;width: 150px;"><br>
  54.             <a href="" onclick="check()" class="button" style="margin-left: 70px;margin-top: 50px;">登录</a>
  55.         </form>
  56.     </div>
  57. </body>
  58. </html>
复制代码
技术咨询-特特 · 2022-6-15 14:52可能调用时机不对,apiready 事件未完成
380
帖子
4
勋章
6
Y币
在哪运行的,是在自定义loader 或 Apploader 中运行的吗
BIP149714 · 2022-6-15 15:02是调用的时机吗,还是定义的位置错了,全部代码在这
1
帖子
0
勋章
11
Y币
调试时和在apploader中运行都会出错
技术咨询-F · 2022-6-15 15:33在哪运行的,是在自定义loader 或 Apploader 中运行的吗
380
帖子
4
勋章
6
Y币
编译自定义loader 运行看看


var user = $api.require('user');   这多个$
BIP149714 · 2022-6-15 16:37调试时和在apploader中运行都会出错
1
帖子
0
勋章
11
Y币
可以了,非常感谢
技术咨询-F · 2022-6-15 16:53编译自定义loader 运行看看


好的
您需要登录后才可以回帖 登录

本版积分规则