首頁  >  文章  >  後端開發  >  linux php下Ajax請求時URL路徑出現重複

linux php下Ajax請求時URL路徑出現重複

WBOY
WBOY原創
2016-08-08 09:23:171169瀏覽

1. 專案用的YII框架,在module下面的Usertest.php有一個方法:

public function getTextArea($fieldName,$usertest_id) {    	      
        return CHtml::activeTextArea($this,$fieldName,array("name"=>$fieldName."_".$usertest_id,'style'=>'rows:3;cols:20;',"ajax" => array("type"=>"POST","url"=>"/usertest/ChangeComments", "data"=>array("usertest_id"=>$usertest_id,"usertest_comments"=>"js:this.value"),"success"=>"js:alert(\"Update comments success!\")")));     
    }
呼叫的地方在usertest/index.php裡面,程式碼如下:

array(
        'name' => 'usertest_comments',
        'id' => 'usertest_comments',
        'header'=>'Comments',
       'type'=>'raw',
        'value'=>'$data->getTextArea(\'usertest_comments\',$data->usertest_id)',
        'htmlOptions'=>array('style'=>'width:100px;'),
       ),

開發在windows上,頁面存取沒有問題,存取路徑是正確的: */usertest/ChangeComments, 但放到Linux上卻變成:*/usertest/usertest/ChangeComments,導致修改不了資料。

2. 試了一下方法,,

①以為是單雙引號的問題,程式碼改成下面這樣:

引號,直接報錯了。後面改回來時windows上竟然也報錯了,跟Linux一樣,無言了。 ②把"url"=>"usertest/ChangeComments"

改成"url"=>"/usertest/H改成"url"=>"/usertest/改成 Linux對大小寫敏感,發現還是不行。 ③後面改成這樣子的:"url"=>"

http://enduserfeedback.ta-mp.com:8080/usertest/c上沒有問題了。結果放到Linux上,發現報錯了, No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://172.24

百度了下,按照這篇文章(點擊了連結)改了之後,點擊連結了。後面把絕對路徑去掉,只留下"dataType"=>"JSONP", 貌似也沒問題。
3. 反正程式總是來回折騰,最後就這樣解決了問題

以上就介紹了linux php下Ajax請求時URL路徑出現重複,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn