以下 jquery 代码在本地服务器上运行良好,但在远程服务器上不起作用。仅供参考,远程服务器正在识别 jquery。我通过我的 Stackoverflow Q 解决了这个问题
请在Merry Flowers 入场页面查看问题页面。当我输入banana8@gmail.com 作为电子邮件ID(在父信息中)并按Tab 键时,应自动填写所有后续表单元素。但这里没有这样做。
以下是来自 chrome 开发者工具的 /students/get_parent_info 的网络标头:
Request URL:http://www.merryflowers.com/students/get_parent_info
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:52
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:CAKEPHP=b0103aa50047806a7063301569298541
Host:www.merryflowers.com
Origin:http://www.merryflowers.com
Referer:http://www.merryflowers.com/students/add
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19
X-Requested-With:XMLHttpRequest
Form Dataview URL encoded
data[MerryParent][email]:banana8@gmail.com
Response Headersview source
Connection:Keep-Alive
Content-Type:text/html; charset=UTF-8
Date:Fri, 20 Apr 2012 18:56:03 GMT
Keep-Alive:timeout=5, max=100
P3P:CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Server:Apache
Transfer-Encoding:chunked
X-Powered-By:PHP/5.2.17
网络响应和预览:
****************************************
仅供参考,我已经验证了 banana8@gmail.com 的现有记录。
在阅读了 lazerblade 的回答后,我检查了 www 和 public_html 文件夹上的 index.php 和 test.php 。我在远程服务器上的根目录是 /home/aquinto1。我很久以前就对这些文件进行了更改。我现在没有在这里修改任何东西。
以下是我的代码:
索引.php
if (!defined('ROOT')) {
define('ROOT', DS.'home'.DS.'aquinto1');
//define('ROOT', dirname(dirname(dirname(__FILE__))));
}
/**
* The actual directory name for the "app".
*
*/
if (!defined('APP_DIR')) {
define('APP_DIR','app');
//define('APP_DIR', basename(dirname(dirname(__FILE__))));
}
/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
//define('CAKE_CORE_INCLUDE_PATH', ROOT);
define('CAKE_CORE_INCLUDE_PATH', DS.'home'.DS.'aquinto1');
}
测试.php
if (!defined('ROOT')) {
define('ROOT', DS.'home'.DS.'aquinto1');
//define('ROOT', dirname(dirname(dirname(__FILE__))));
}
/**
* The actual directory name for the "app".
*
*/
if (!defined('APP_DIR')) {
define('APP_DIR','app');
//define('APP_DIR', basename(dirname(dirname(__FILE__))));
}
/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
//define('CAKE_CORE_INCLUDE_PATH', ROOT);
define('CAKE_CORE_INCLUDE_PATH', DS.'home'.DS.'aquinto1');
}
<script type="text/javascript">
//var j=jQuery.noConflict();
$(document).ready(function(){
$("#MerryParentEmail").change(function(){
//txt=$("#MerryParentEmail").val();
email_id=$("#MerryParentEmail").serialize();
$.post("/students/get_parent_info",email_id,function(result_str){
result_array=result_str.split('*****');
$("#MerryParentInitial").val(result_array[0]);
$("#MerryParentName").val(result_array[1]);
$("#MerryParentLandline").val(result_array[2]);
$("#MerryParentMobile").val(result_array[3]);
$("#MerryParentAddress").val(result_array[4]);
$("#MerryParentStateId").val(result_array[5]);
state=result_array[5];
txt_str="state_id="+state;
$.get("/students/getcities",txt_str,function(result){
$("#MerryParentCityId").html(result).show();
$("#MerryParentCityId").val(result_array[6]);
});
$("#MerryParentPostalCode").val(result_array[7]);
});
});
$("#MerryParentStateId").change(function(){
state=$(this).val();
txt_str="state_id="+state;
$.get("/students/getcities",txt_str,function(result){
$("#MerryParentCityId").html(result).show();
});
});
});
</script>
student_controller 的 get_parent_info 函数和 getcities 函数:
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'].'*****';
}
}
function getcities(){
$this->data['MerryParent']['state_id']=$_GET['state_id'];
if (!empty($this->data['MerryParent']['state_id'])){
$cities = $this->Student->MerryParent->City->getCities($this->data['MerryParent']['state_id']);
//print_r($cities);
foreach ($cities as $k=>$v){
echo '<option value="'.$k.'">'.$v.'</option>';
}
/* foreach($cities as $optionValue){
echo '<option>' . $optionValue . '</option>';
}*/
}else{
$this->Session->setFlash('You didn\'t select a state!');
}
}