Javascript $http()不是一个函数 输入Where条件: 去 函数myFunction($http){ var条件=document.getElementById(“myText”).value; $http({ 方法:“POST”, url:“http://localhost:8080/peter/peter1/where", 参数:{“where”:条件}, 标题:{'Content-Type':'application/json'} }); }
当我试着调试上面的代码时,我得到一个错误 $http不是一个函数。。。在上面的代码中,我得到了一个错误 说$http不是函数..请帮我解决这个问题Javascript $http()不是一个函数 输入Where条件: 去 函数myFunction($http){ var条件=document.getElementById(“myText”).value; $http({ 方法:“POST”, url:“http://localhost:8080/peter/peter1/where", 参数:{“where”:条件}, 标题:{'Content-Type':'application/json'} }); },javascript,html,angularjs,ajax,Javascript,Html,Angularjs,Ajax,当我试着调试上面的代码时,我得到一个错误 $http不是一个函数。。。在上面的代码中,我得到了一个错误 说$http不是函数..请帮我解决这个问题 Enter Where Condition: <input type="text" id="myText"> <button onclick="myFunction($my_http)">Go</button> <script type="text/javascript"> function myFun
Enter Where Condition: <input type="text" id="myText">
<button onclick="myFunction($my_http)">Go</button>
<script type="text/javascript">
function myFunction($http) {
var condition = document.getElementById("myText").value;
$http({
method: 'POST',
url: "http://localhost:8080/peter/peter1/where",
params: {"where":condition},
headers: {'Content-Type': 'application/json'}
});
}
<script/>
但事实并非如此:
myFunction();
是一种可以在使用时注入的服务
现在代码中的内容无法使用,因为您定义了一个函数,该函数需要一个名为$http
的参数,而您尚未传递该参数
除此之外,它还希望$http
参数是一个接受对象的函数,该对象可能会将数据发布到服务器
下面是一个关于如何在Angular中完成您要做的事情的示例
这是一个由egghead.io编写的,我非常喜欢它您包含了什么javascript库来定义$http函数?您使用的是angular js吗,这是您定义的变量吗?我使用的是angularjs
而不是
-
您没有向函数传递任何内容,因此参数是未定义的。我认为您需要先知道angularjs是如何工作的
myFunction();