1,247   jQuery JS

ajax发送请求之前,添加一些参数

	  $(document).ajaxSend(function (event,xhr,options) {
	  	var type = options.type.toUpperCase();
	    if (type == 'POST') {
	      	if(xhr.setRequestHeader){
	      		xhr.setRequestHeader('csrf-token', csrfToken);
	      	}else{
	      		options.data['_csrf'] = csrfToken;
	      		
	      		if(options.url.indexOf("?") == -1){
	      			options.url = options.url+"?_csrf="+csrfToken;
	      		}else{
	      			options.url = options.url+"&_csrf="+csrfToken;
	      		}
	      	}
	    }
	  });




Leave a Reply

Your email address will not be published. Required fields are marked *