linux php下Ajax请求时URL路径出现重复

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. 尝试了一下方法,,

①以为是单双引号的问题,代码改成下面这样:

    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!\")")));     
    }
问题还是没有解决,又改成单引号,直接报错了。后面改回来时windows上竟然也报错了,跟Linux一样,无语了。

②把"url"=>"usertest/ChangeComments"改成"url"=>"/usertest/changeComments", Linux对大小写敏感,发现还是不行。

③后面改成这样子的:"url"=>"http://enduserfeedback.ta-mp.com:8080/usertest/changeComments",windows上没有问题了。结果放到Linux上,发现报错了,

 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://172.24

百度了下,按照这个文章(点击打开链接)改了之后,可以了。后面把绝对路径去掉,只留下"dataType"=>"JSONP", 貌似也没有问题。

3. 反正程序总是来回折腾,最后就这样解决了问题



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值