以下jquery和cakephp代码在我的localhost上工作正常,提醒正确的result_str,但它在远程服务器上不起作用。我已经在localhost和远程服务器的末尾包含了输出。
post方法正常,但没有远程显示正确的输出。
我已经验证了我输入的电子邮件ID是否存在于远程数据库中。
merry_parent模型中的调试($ merryparent_info)本地和远程都没有显示。
当用户输入父信息电子邮件ID并按下标签按钮时,会弹出2个警告框。第一个显示post方法中传递的email_id,第二个警告显示result_str。
有人可以告诉我我哪里出错了。过去4天我一直试图解决这个问题。谢谢。
<script type="text/javascript">
$(document).ready(function(){
$("#MerryParentEmail").change(function(){
//txt=$("#MerryParentEmail").val();
email_id=$("#MerryParentEmail").serialize();
$.post("/students/get_parent_info",email_id,function(result_str){
alert("result_str: "+result_str);
});
});
</script>
students_controller.php
function get_parent_info(){
//$this->layout=false;
if (!empty($this->data)){
$merryparent_info=$this->Student->MerryParent->getMerryParents($this->data['MerryParent']['email']);
print_r($merryparent_info);
echo $merryparent_info['MerryParent']['initial'].'*****';
echo $merryparent_info['MerryParent']['name'].'*****';
echo $merryparent_info['MerryParent']['landline'].'*****';
echo $merryparent_info['MerryParent']['mobile'].'*****';
echo $merryparent_info['MerryParent']['address'].'*****';
echo $merryparent_info['MerryParent']['state_id'].'*****';
echo $merryparent_info['MerryParent']['city_id'].'*****';
echo $merryparent_info['MerryParent']['postal_code'].'*****';
}
}
merry_parent.php模型
function getMerryParents($field_value){
if (is_int($field_value))
$conditions=array('merryParent.id'=>$field_value);
else
$conditions=array('merryParent.email'=>$field_value);
//debug($conditions);
$merryparent_info=$this->find('first',array(
'conditions'=>$conditions,
'recursive'=>-1 //fetches merry_parents table data only not the associated data
));
debug($merryparent_info);
return $merryparent_info;
}
localhost输出:
第一次提醒
email_id: data%5BMerryParent%5D%5Bemail%5D=banana8%40gmail.com
第二次提醒
result_str: Array
(
[MerryParent] => Array
(
[id] => 38
[initial] => Ms
[name] => banana kaur
[username] => banana8
[email] => banana8@gmail.com
[password] => 7b311dc3e6d4862caf024b65410c793adfc530bc
[landline] =>
[mobile] => 8487234783
[address] => 99 fruits road
[state_id] => 14
[city_id] => 81
[postal_code] => 877979
[created] => 2012-02-08 05:24:49
[modified] => 2012-02-15 15:46:05
)
)
Ms*****banana kaur**********8487234783*****99 fruits road*****14*****81*****877979*****
远程服务器输出:
第一次提醒
email_id: data%5BMerryParent%5D%5Bemail%5D=banana8%40gmail.com
第二次提醒
result_str: ****************************************
答案 0 :(得分:0)
好的,问题出在代码MerryParent Model上。我的jquery代码没有任何问题。
在MerryParent模型中,
function getMerryParents($field_value){
if (is_int($field_value))
$conditions=array('merryParent.id'=>$field_value);
else
$conditions=array('merryParent.email'=>$field_value);
//debug($conditions);
$merryparent_info=$this->find('first',array(
'conditions'=>$conditions,
'recursive'=>-1 //fetches merry_parents table data only not the associated data
));
debug($merryparent_info);
return $merryparent_info;
}
我将merryParent.id更改为MerryParent.id,将merryParent.email更改为MerryParent.email,它现在可以在远程服务器上运行。