Ajax调用throw" TypeError:object不是函数"例外

时间:2016-06-11 06:01:13

标签: jquery ajax intel-xdk uncaught-typeerror

此代码抛出TypeError 我们的想法是从远程外部服务器获取salt并将其附加到密码并生成哈希。 问题是代码抛出了一个说

的TypeError
  

TypeError:object不是函数

以下是index_user_scripts.js的一部分。



/*jshint browser:true */
/*global localStorage, console, $ */
(function(){
 "use strict";
 /*
 * hook up event handlers 
 */
 function register_event_handlers(){
    $(document).ready(function(){
      try {
        if(!window.openDatabase) {
          console.log('Local Databases are not supported by your browser.');
        } else {
          var shortName = 'ChtrShk';
          var version = '1.0';
          var displayName = 'ChhatraSahayak';
          var maxSize = 2*1024*1024;
          var db = window.openDatabase(shortName, version, displayName, maxSize);
          }
      } catch(e) {
        if (e == 2) {
          // Version mismatch.
          console.log("Invalid database version.");
        } else {
          console.log("Unknown error "+ e +".");
        }
        return;
      }
      if ( localStorage.getItem("isLogged") === true ){
        $("#cs_now")[0].click();
      }else{
        localStorage.clearData;
        console.log("We haven\'t logged-in yet. Let\'s login.");
        console.log(window.location.pathname);
        window.location = "index.html#login";
      }
    });   
        /* button  #login */
    $(document).on("click", "#signin", function(evt)
    {
      if ($("[name=lg_pass]")[0].value === "" || $("[name=lg_roll]")[0].value === ""){return false;}
      console.log($("[name=lg_roll]")[0].value);
      console.log($("[name=lg_pass]")[0].value);
      var salt = '';
      try{
          $.ajax({
              async: true,
              crossDomain: true,
              url:"http://borngeek.tk/cs/in.php",
              type:"POST",
              dataType:"jsonp",
              timeout: 5000,
              success: function(response){
                salt = response._s;
                console.log("Success: Fetched salt. " + salt);
              },
              error: function(data){
                console.error("Error: Failed to fetch salt.");
              }
           });
      }catch(e){console.error(e.name + ": " + e.message);}
      console.log("checkpoint.");
      var passStr = $("[name=lg_pass]")[0].value.concat(salt);
      passStr = hex_sha512(passStr);
      console.log(passStr);
      try{
       $.ajax({
           async: true,
           crossDomain: true,
           url:"http://borngeek.tk/cs/in.php",
           type:"POST",
          data:{"roll":$("[name=lg_roll]")[0].value,
             "pass":passStr,
             "salt":$("[name=lg_salt]")[0].value
           },
           success: function(response){console.log("Login successful.");},
          error: function(response){console.log("Bad login attempt.");}
        });
      }catch(e){console.error(e.name + ": " + e.message);}
      console.log("Login Attempt.");
      return false;
    });
 }
 document.addEventListener("app.Ready", register_event_handlers, false);
})();




1 个答案:

答案 0 :(得分:0)

只需扫描该代码中的函数调用,window.openDatabase(...)似乎是最有可能的候选者。似乎Web SQL数据库API并未得到广泛支持,如this similar question的已接受答案中所述。