我尝试为Symfony 2上传ajax脚本.Chrome返回此错误:
未捕获的TypeError:非法调用jquery.min.js:4
我认为这是由于FormData对象没有正确构造(我尝试使用以下脚本.serialized():
$(document).ready(function() {
$('#formImage').submit(function(event) {
event.preventDefault();
// appel Ajax
alert("ajax");
var input = document.getElementById("rasta_blogbundle_imagetype_file");
console.log(input);
var formdata = false;
if (window.FormData) {
formdata = new FormData();
console.log('formdata initialized ...');
}
else{
console.log('formdata not supported');
}
formdata.append('name',$('#rasta_blogbundle_imagetype_name').val());
console.log(formdata);
formdata.append('file',input);
formdata.append('_token',$('#rasta_blogbundle_imagetype__token').val());
console.log(formdata);
//alert(DATA);
if (formdata){
$.ajax({
url: $(this).attr('action'), // le nom du fichier indiqué dans le formulaire
type: $(this).attr('method'), // la méthode indiquée dans le formulaire (get ou post)
cache: false,
//data : $(this).serialize(),
data: …Run Code Online (Sandbox Code Playgroud) 编辑/更新:
我在角度1.6(正常方式)中忘记了原始代码:
http://codepen.io/darkiron/pen/qRJmaj
我想,这可以帮助你.我的工作是转换为EcmaScript ES6.
谁工作得很好!
如何$watch在ES6 Angular控制器中使用?
loginaction(){
this.$scope.$watch('ui.shake', this.resetUiCheck());
....
}
Run Code Online (Sandbox Code Playgroud)
我试试这个,结果不是预期的
resetUiCheck(newValue, oldValue){
console.log(this.ui.shake);
return () => {
alert('foo');
console.log(this);
if(this.ui.shake == true){
this.$timeout(function(){
this.ui.shake = false;
}, 1000);
}
};
}
Run Code Online (Sandbox Code Playgroud)
总是假的!
我试试这个:
this.$scope.$watch('ui.shake', this.resetUiCheck);
Run Code Online (Sandbox Code Playgroud)
结果是这个错误
TypeError:无法读取未定义的属性'ui'
另一个问题:$watch不应该在Contoller构造函数中设置该函数?