Javascript Jquery-ajax-post、get等都不';不行?
Javascript:Javascript Jquery-ajax-post、get等都不';不行?,javascript,jquery,ajax,post,get,Javascript,Jquery,Ajax,Post,Get,Javascript: function openEditor(){ $("#editor").show().animate({width: 965, height: 380}, 1500); $("#editor textarea").show(); } function closeEditor(){ $("#editor").animate({width: 985, height: 1}, 1500, function(){ $("#editor")
function openEditor(){
$("#editor").show().animate({width: 965, height: 380}, 1500);
$("#editor textarea").show();
}
function closeEditor(){
$("#editor").animate({width: 985, height: 1}, 1500, function(){
$("#editor").hide();
$("#editor textarea").hide();
});
}
function setedit(){
$.ajax({
type: "POST",
url: "engine.php",
data: "title="+ $('title').val() +"&text="+ $('text').val(),
success: function(msg){
alert("Saved.");
closeEditor();
search();
}
beforeSend: function(){
$('#mainField').html('<img src="data/images/loader.gif" alt="Loading...">');
}
});
}
function search(){
$.get('engine.php?search='+ $('#search').val() , function(data) {
$('#mainField').html(data);
});
}
大家好
我想用ajax搜索文章,并在一个字段中获取这些文章的内容。我还想使这些文章可编辑。。。但整个事情都不管用
打开编辑器的功能不起作用。。。当我想搜索并按下搜索按钮时,我进入engine.php。。。我无法尝试编辑,因为我无法打开编辑框
怎么了?为什么不起作用
这里有一把小提琴:
问候语您的提交函数不会返回true或false,因此它将被提交。 您的操作是engine.php 返回false以停留在站点上
function setedit(){
...
return false;
}
我必须补充一点,您将表单和ajax混合在一起,这是不好的
绑定触发函数的单击事件比使用内联事件处理程序更好。您自己也看过错误吗?在发送之前没有逗号为什么表单和Ajax混合会很糟糕?如果您想遵循不引人注目的JavaScript指导原则,那么这是一种方法。如果没有,那么就没有必要删除内联事件处理程序。也许是因为他们更难追踪,对他的情况来说并不重要。另外,
function setEdit(event){…event.preventDefault();}
是使用jQuery实现这一点的方法。如果你弄错了,你很快就会失去概览。。只是我的经验;-)
#editor {
display: none;
background: #F0F0F0;
}
span.edit {
font-size: 25px;
}
#editor textarea {
width: 950px;
height: 250px;
display: none;
}
.toolbox {
float: right;
}
function setedit(){
...
return false;
}