发送数据通过JSON(AJAX功能),但不能访问
的控制器这是我已经包含在HEAD标记自己的JavaScript函数:发送数据通过JSON(AJAX功能),但不能访问
function test()
{
//enter code here
$.ajax({
url: 'test?msgto='+document.getElementById('Select1').value,
dataType: 'json',
type : 'GET',
success: function(result)
{
// console.log(result);
alert('test1');
// alert(string(result[0]['Select1']));
// alert(result[0]['TextArea1']);
//document.getElementById('Text1').Value = ;// string(result[0]['location']);
}
});
}
,我想将数据发送到我的PHP控制器在按钮的Cilck事件上使用此功能。我写了下面的代码的getAction()
// TODO Auto-generated method stub
//echo('Get');
$msgfrom = 1; //$this->_getparam('usrid');
$msgto = $this->_getparam('msgto');
$sql = "call select_messages(".$msgfrom.",".$msgto.");";
$data = Zend_Db_Table::getDefaultAdapter()->query($sql)->fetchAll();
$this->_helper->json($data);
不过,虽然上点击我没有得到任何输出或结果.... 请尽快引导我..... :)
存在一些误用。
首先,你确定GETACTION()获取/ test路径吗?其次,在你的JS代码中,我不确定你是否正确地调用了正确的路径。在url
参数的开始
$.ajax({
type: 'GET',
url: '/test', // Notice the '/' at the beginning
data: {
msgto: $('#Select1').val(), // Since you're using jQuery, do it all the way :)
}
success: function(result) {
alert(result);
}
});
注意斜线:
你最好使用这个。这意味着:“在域名后面开始”。另外,当您使用jQuery时,您不需要使用详细的document.getElementById()
:)。
最后,请参阅data
参数。 jQuery将在发送AJAX请求之前自动构建正确的URL。我认为它可以让你的代码更清洁。
嗨戴维斯,真的thanx你的关注....我已经使用上述代码提供的你.... !!布现在它的显示(在控制台的铬)“测试没有定义”....并且以某种方式引导我,以及如何检查它的输出..... !! – user1206552 2012-02-13 11:47:17
嗨,我不是戴维斯:)看起来你忘了'/ test'的引号。检查你的代码。 – 2012-02-13 12:48:29
什么是HTML的样子。你可以张贴其中的一部分陈述Select1。行动的路径应该是相对的/测试/?可以这是一个问题 – 2012-02-13 10:44:27