发表于: 2017-04-17 20:51:05
3 1097
今天完成的事情:
1 配置好本机nginx。
2 使用jq的ajax的post方法成功发送登陆账号,密码数据,后台返回登录信息。
明天的计划:
开始任务6,当然先学习一波angula。
遇到的问题:
1 配置nginx。
我的问题比较奇怪,早在css任务2的时候,我就按照古尘师姐的知乎帖子配置好了,输入localhost也有欢迎页,也可以访问相关页面,但是这两天再输入localhost,老是出现iis页面,以下:
解决方法:
①取消iis服务
②上一步仅仅取消了iis服务,但是ng还是老报错,然后又搜索了一大堆教程,主要有以下修改端口的方法:
但是不奏效,修改了几次(改为0,1 ,4等等),最终能正常使用是这样的:
③在配置反向代理跨域时又报错了,以下直接给出正确的nginx.conf代码:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logsinx.pid;
events {
worker_connections 1024;
}
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 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 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$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }#}
//主要时以下这段代码的三个更改,复制时记得删除注释。
server {
listen 1002; //更改1
server_name localhost;
location /{
root E:/css/js5; //更改2 “E:/css/js5这里不要用反斜杠\”
index js5.html index.htm; //更改3
try_files $uri $uri/ /index.html =404;
}
location /carrots-admin-ajax/{
proxy_pass http://dev.admin.carrots.ptteng.com/;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
输入localhost:1002即可看到E:/css/js5/js5.html文件了。
(以上代码是我复制9哥的,此处非常感谢9哥和小Y的帮助,帮我一步步查看问题,这种配置问题有时候真的很烦,第一次进行配置总有需要莫名其妙的问题。)
2 申明变量, 赋值。
错误代码:
var userName = $("#name").val();
$('#name').mouseleave(function () {
if (userName == ''){
$('.remind').eq(0).css('visibility','hidden');
}else {
if (regUsername.test(userName) == false ){
$('.remind').eq(0).css('visibility','visible');
}
}
});
因为后面要使用到userName的值(即输入框获取的值),所以使用全局变量表示,但在调试中发现$获取的值始终是“”,使得userName一直等于“”。
原因:因为userName是在函数外面申明的变量,页面加载完毕$立即获得一个值,当在input框内进行输入操作时,此时已经晚了。正确的写法:
var userName;
var passWord;
$('#name').mouseleave(function () {
userName = $('#name').val();
if (userName == ''){
$('.remind').eq(0).css('visibility','hidden');
}else {
if (regUsername.test(userName) == false ){
$('.remind').eq(0).css('visibility','visible');
}
}
});
其实外面不用var userName,函数内部直接userName = $('#name').val()也可以直接申明一个全局变量,但是这样做不推荐,有一个明显的缺点是(js高程):
虽然省略var操作符可以定义全局变量,但这也不是我们推荐的做法。因为在局部作用域中定义的全局变量很难维护,而且如果有意的忽略了var操作符,也会由于相应变量不会马上就有定义而导致不必要的混乱。给未经生命 的变量赋值在严格模式下会导致抛出ReferenceError错误。
收获:
1 以上及任务5完成。
2 使用postman。翻墙可以使用loco加速器,每天2小时4M带宽。在谷歌商店搜索postman,记得下载那个下载量最多的postman,我9哥下载了一个假的postman,进沟了。使用时直接post,输入测试接口看返回数据即可。
评论