Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

珍爱网2017春前端笔试题 #27

Open
WarpPrism opened this issue Mar 17, 2017 · 0 comments
Open

珍爱网2017春前端笔试题 #27

WarpPrism opened this issue Mar 17, 2017 · 0 comments
Labels

Comments

@WarpPrism
Copy link
Owner

跨域请求如何发送cookie

服务端修改返回头:

response.setHeader('Access-Control-Allow-Credentials', true);
response.setHeader('Access-Control-Allow-Origin', 'other-domain.com'); // 不能设置为*

前端:

$.ajax({
	type: 'get/post',
	url: 'url',
	async: true,
	xhrFields: {withCredentials: true}
	crossDomain: true
});
// 原生js
xhr.withCredentials = true;
//withCredentials属性用于跨域请求中允许携带凭据信息

grid布局

用HTML+CSS实现如下样式布局:

codepen demo

ajax请求中get和post的区别

  • 根据HTTP规范,GET用于信息获取,而且应该是安全的和幂等的。POST表示可能修改变服务器上的资源的请求
  • GET请求的数据会附在URL之后(就是把数据放置在HTTP协议头中),以?分割URL和传输数据,参数之间以&相连,POST把提交的数据则放置在是HTTP包的包体中。
  • GET方式提交的数据最多只能是1024字节,理论上POST没有限制,可传较大量的数据
  • POST的安全性要比GET的安全性高,使用get容易产生CSRF风险

参考

如何判断一个Object是否为空

// jQuery isEmptyObject()
function isEmptyObject(e) {  
    var t;  
    for (t in e)  
        return !1;  
    return !0;
}  
// 第二种
var obj = {};
if (JSON.stringify(obj) == '{}')
	return true;

写一个闭包的例子

// 单例模式
var singleton = function(fn) {
    var obj;
    return function() {
        console.log(this, arguments);
        return obj || (obj = fn.apply(this, arguments));
    }
}

var createMask = singleton(function() {
    return document.body.appendChild(document.createElement('div'));
});
console.log(createMask());
// 例二
var lis = document.querySelectorAll('ul.test li');
for (var i = 0; i < lis.length; i++) {
	lis[i].onclick = (function(ii) {
        return function() {
            console.log(ii);
        };
    })(i);
}
@WarpPrism WarpPrism added the Life label Mar 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant