以下jquery代碼在本地服務器上正常工作,但在遠程服務器上無法正常工作。 FYI遠程服務器正在認識jQuery。我通過My Stackoverflow Qjquery post並獲取遠程服務器上不工作的方法
請檢出問題頁面Merry Flowers Admission Page。當我輸入[email protected]作爲電子郵件ID(在父信息中)並按Tab鍵時,所有後續表單元素應該自動填充。但是這裏沒有這樣做。
以下是來自Chrome的開發者工具的網絡標頭/學生/ 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]:[email protected]
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
網絡響應和預覽:
****************************************
僅供參考,我已經證實沒有存在記錄爲[email protected]。
在閱讀lazerblade的回答後,我檢查了www和public_html文件夾中的index.php和test.php。我在遠程服務器上的根目錄是/ home/aquinto1。我早已對這些文件進行了更改。我現在在這裏沒有修改任何東西。
下面是我的代碼:
的index.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');
}
test.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>
students_controller的get_parent_info FUNC和getcities FUNC:
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!');
}
}
好的,我讓阿賈克斯在我的域名獲取和發佈請求。它不是跨域。/students/get_parent_info和/ students/get_cities都在我的域中。 – vaanipala 2012-04-19 00:49:21
正如我在我的問題中提到的,我的域名是http://www.merryflowers.com。 get_parent_info和getcities函數通過模型從數據庫表中檢索數據。 – vaanipala 2012-04-19 09:07:16