First I used the symfonyhttp-foundation component.
Ajax Request Side:
$.ajax({ url: jsui.www + 'comment/add', data: $(this).serialize(), type: $(this).attr('method'), error: function(request) { $('.comt-loading').slideUp(300); $('.comt-error').slideDown(300).html(request.responseText); }, success: function(data) {...} ...
PHP Response End:
public function add(){ //header('HTTP/1.1 405 Method Not Allowed'); //echo 'Content'; //exit; //这样写也返回200 $response = new Response( 'Content405!', Response::HTTP_METHOD_NOT_ALLOWED, array('content-type' => 'text/html') ); //var_dump($response);die(); return $response; }
Nginx Configuration:
HTTP {include mime.types; Default_type Application/octet-stream; #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sent "$http _referer" ' # ' "$http _user_agent" "$http _x_forwarded_for"; #access_log Logs/access.log Main; Sendfile on; #tcp_nopush on; #keepalive_timeout 0; Keepalive_timeout 65; #gzip on; server {listen 8080; server_name localhost; #charset Koi8-r; #access_log Logs/host.access.log Main; Location/{root E:\Nginx\www; Index index.html index.htm index.php; if (!-e $request _filename) {#一级目录下 #rewrite ^/(. *) $/index.php/$1 last; #域名下的二级目录 rewrite ^/newblog/web/(. *) $/newblog/web/index.php/$1 last; }} #error_page 404/404.html; # REDIRECT Server errorPages to the static page/50x.html # Error_page 502 503 504/50x.html; Location =/50x.html {root html; } # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {# ProX Y_pass http://127.0.0.1; #} # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php { Root E:\Nginx\www; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_split_path_info ^ (. +\.php) (. *) $; #增加这一句 Fastcgi_param path_info $fastcgi _path_info; #增加这一句 Fastcgi_param script_filename $document _root$fastcgi_script_name; Include Fastcgi_params; }
This is the return
Reply content:
First I used the symfonyhttp-foundation component.
Ajax Request Side:
$.ajax({ url: jsui.www + 'comment/add', data: $(this).serialize(), type: $(this).attr('method'), error: function(request) { $('.comt-loading').slideUp(300); $('.comt-error').slideDown(300).html(request.responseText); }, success: function(data) {...} ...
PHP Response End:
public function add(){ //header('HTTP/1.1 405 Method Not Allowed'); //echo 'Content'; //exit; //这样写也返回200 $response = new Response( 'Content405!', Response::HTTP_METHOD_NOT_ALLOWED, array('content-type' => 'text/html') ); //var_dump($response);die(); return $response; }
Nginx Configuration:
HTTP {include mime.types; Default_type Application/octet-stream; #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sent "$http _referer" ' # ' "$http _user_agent" "$http _x_forwarded_for"; #access_log Logs/access.log Main; Sendfile on; #tcp_nopush on; #keepalive_timeout 0; Keepalive_timeout 65; #gzip on; server {listen 8080; server_name localhost; #charset Koi8-r; #access_log Logs/host.access.log Main; Location/{root E:\Nginx\www; Index index.html index.htm index.php; if (!-e $request _filename) {#一级目录下 #rewrite ^/(. *) $/index.php/$1 last; #域名下的二级目录 rewrite ^/newblog/web/(. *) $/newblog/web/index.php/$1 last; }} #error_page 404/404.html; # REDIRECT Server errorPages to the static page/50x.html # Error_page 502 503 504/50x.html; Location =/50x.html {root html; } # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {# ProX Y_pass http://127.0.0.1; #} # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php { Root E:\Nginx\www; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_split_path_info ^ (. +\.php) (. *) $; #增加这一句 Fastcgi_param path_info $fastcgi _path_info; #增加这一句 Fastcgi_param script_filename $document _root$fastcgi_script_name; Include Fastcgi_params; }
This is the return
This should be okay with nginx.