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

php中文网
发布: 2016-08-08 09:23:17
原创
1387人浏览过

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. 反正程序总是来回折腾,最后就这样解决了问题

降重鸟
降重鸟

要想效果好,就用降重鸟。AI改写智能降低AIGC率和重复率。

降重鸟 113
查看详情 降重鸟

立即学习PHP免费学习笔记(深入)”;

以上就介绍了linux php下Ajax请求时URL路径出现重复,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号