Jquery 使用时间间隔zend框架的Ajax调用
我想做的基本上是每3秒钟检索一次div和sub-div内容。我正在使用ajax将数据发送到控制器。但是我越来越Jquery 使用时间间隔zend框架的Ajax调用,jquery,ajax,zend-framework,request,nstimeinterval,Jquery,Ajax,Zend Framework,Request,Nstimeinterval,我想做的基本上是每3秒钟检索一次div和sub-div内容。我正在使用ajax将数据发送到控制器。但是我越来越 $.ajax is not a function http://localhost/index/editor Line 25 这是我正在使用的代码 <script type="text/javascript"> window.setInterval(getAjax, 3000); function getAjax() { $.ajax({
$.ajax is not a function
http://localhost/index/editor
Line 25
这是我正在使用的代码
<script type="text/javascript">
window.setInterval(getAjax, 3000);
function getAjax() {
$.ajax({
type: "POST",
url: 'localhost/index',
data: "some-data"
});
}
</script>
setInterval(getAjax,3000);
函数getAjax(){
$.ajax({
类型:“POST”,
url:'本地主机/索引',
数据:“一些数据”
});
}
1) 我做错了什么
2) 如何在zend controller中接收数据。ajax由jQuery定义。在调用此函数之前必须包含它。
$。ajax
由jQuery定义。调用此函数之前必须包含它。一旦页面中包含了jQuery,就可以使用$.ajax()函数。之后,在控制器中,可以访问$\u POST变量中的数据。为了方便起见,我通常使用JSON对象向控制器发送数据:
<script type="text/javascript">
window.setInterval(getAjax, 3000);
var data = {};
data['field1'] = 'value1';
data['field2'] = 'value2';
function getAjax() {
$.ajax({
type: "POST",
url: 'localhost/index',
data: data
});
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript">
编辑:
哦,我忘了,您可能需要检查控制器从jQuery代码发送的响应。您可以通过以下方式实现这一点
$.ajax({
//...
success: function(jsonResp) {
if(jsonResp['isValid']) alert(jsonResp['gotValue']);
}
});
一旦jQuery包含在页面中,就可以使用$.ajax()函数。之后,在控制器中,可以访问$\u POST变量中的数据。为了方便起见,我通常使用JSON对象向控制器发送数据:
<script type="text/javascript">
window.setInterval(getAjax, 3000);
var data = {};
data['field1'] = 'value1';
data['field2'] = 'value2';
function getAjax() {
$.ajax({
type: "POST",
url: 'localhost/index',
data: data
});
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript">
编辑:
哦,我忘了,您可能需要检查控制器从jQuery代码发送的响应。您可以通过以下方式实现这一点
$.ajax({
//...
success: function(jsonResp) {
if(jsonResp['isValid']) alert(jsonResp['gotValue']);
}
});
您是否包含jQuery(或Zepto)?jQuery包含在我的默认布局中,我禁用了它。这会影响吗?您是否包含jQuery(或Zepto)?jQuery包含在我的默认布局中,我禁用了它。这有什么影响?