Home > Backend Development > PHP Tutorial > URL paths are repeated during Ajax requests under linux php

URL paths are repeated during Ajax requests under linux php

WBOY
Release: 2016-08-08 09:23:17
Original
1216 people have browsed it

1. The YII framework used in the project has a method in Usertest.php under the module:

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!\")")));     
    }
Copy after login
is called in usertest/index.php, the code is as follows:

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

is developed on windows, and there is no page access Problem, the access path is correct: */usertest/ChangeComments, But when put on Linux, it becomes: */usertest/usertest/ChangeComments, resulting in the data being unable to be modified.

2. I tried the method,

① I thought it was a problem with single and double quotation marks, so I changed the code to the following:

    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!\")")));     
    }
Copy after login
The problem was still not solved, so I changed it to single quotation marks again. Quotation marks, an error is reported directly. When I changed it back later, an error was also reported on Windows. It was the same as Linux. I was speechless.

②Change "url"=>"usertest/ChangeComments" to "url"=>"/usertest/changeComments", Linux is case sensitive, but it still doesn't work.

③Then change it to this: "url"=>"http://enduserfeedback.ta-mp.com:8080/usertest/changeComments", There is no problem on windows. The result was put on Linux and an error was reported,

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

Baidu, after changing it according to this article (click to open the link), it's OK . Later, I removed the absolute path and left only "dataType" => "JSONP", which seemed to be no problem.

3. Anyway, the program always went back and forth, and finally the problem was solved like this

The above introduces the duplication of URL paths during Ajax requests under Linux PHP, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template