2015-10-20 92 views
0

我想运行/调用将要更新数据库的PHP文件。不能调用PHP脚本

铬是给我这个错误:enter image description here

我使用此代码为我index.html文件:

<!DOCTYPE html> 
<html> 
<body> 
    <input type="text" id="descriptioninput"> 
    <input type="number" id="budgetin"> 
    <input type="number" id="budgetout"> 
    <button type="button" onclick="addToDB()">Add to database</button> 

    <script> 
     function addToDB() 
     { 
      var descriptioninput = document.getElementById('descriptioninput').value; 
      var budgetin = document.getElementById('budgetin').value; 
      var budgetout = document.getElementById('budgetout').value; 

      $.ajax ({ 
       TYPE: 'POST', 
       url: 'addtodb.php', 
       data:{descriptioninput:descriptioninput, budgetin:budgetin, budgetout:budgetout}, 
       success:function (data) { 
        // Completed successfully 
        alert('success!'); 
       } 
      }); 
     } 
    </script> 
</body> 
</html> 

什么我错在这里做什么?我试图把在<head>元素的代码,并指定type="text/javascript"

+0

你没有包含'jQuery'..add this'https:// code.jquery.com/jquery-1.11.3.min.js' –

回答

1

你忘了引用jquery在代码。在本地添加或使用CDN

https://code.jquery.com/jquery-1.11.3.min.js 
1

增加提及的jQuery然后remeber:JavaScript是区分大小写的。更改TYPEtype

$.ajax ({ 
    type: 'POST', 
    url: 'addtodb.php', 
    data:{descriptioninput:descriptioninput, budgetin:budgetin, budgetout:budgetout}, 
    success:function (data) { 
     // Completed successfully 
     alert('success!'); 
    } 
}); 
1

此功能$.ajax()属于以所谓的jQuery JavaScript库,你应该在你的头块这个库。

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>