我正在构建一个php程序,从网站获得3个变量并计算它们,然后发布结果,我可以读取变量,计算它们,但发布部分对我来说很困难,因为它使用Ajax表单(我认为)可以使用XMLhttprequest使用php进行发布?用php提交一个ajax表格
这是提交按钮:
<a href="#" class="formSubmit" tabindex="3">
这个消息框:
<textarea name="message" id="messageContent" rows="18" wrap="virtual" tabindex="2"></textarea>
我试图处理它像一个普通的形式,但它没有工作,我跟踪顺着AJAX功能发布:
function formSubmitFunction(e,action, target){
e.stopPropagation();
e.preventDefault();
if ($("#messageContent").attr("value") == undefined || $("#messageContent").attr("value").length < 2){
alert("A mensagem precisa ter no mÃnimo 2 caracteres.");
$("#messageContent").focus();
return false;
}else {
$("#formSubmit").html('<img src="http://website.com/'+desTheme+'/images/send_post.gif');
if(action == "post"){
$("#formAjax").append('<div id="carregando"></div>');
PostFunctions.insertPost(topicId,$("#messageContent").val(), callbackInsertPost);
} else {
var postId = target.replace("#","");
$("#formAjax").append('<div id="carregando"></div>');
PostFunctions.editPost(postId,$("#messageContent").val(), callbackEditPost);
}
return false;
}
}
帮助
@edit:
发现其他insertPost功能
function callbackInsertPost(response){
var result = eval("("+response+")");
if($("#popup").length){
$("#popup").remove();
}
if(!result.error){
var returnMessage = "";
if(result.isForumModerated){
returnMessage = '<div id="popup" class="autoClear simple">'
+'Sua mensagem está aguardando a aprovação da moderação.'
+'</div>';
$("#carregando").remove();
$(actualPostId).prepend(returnMessage);
window.setTimeout(function(){
$("#popup").fadeOut("slow", function(){
$("#popup").remove();
});
},5000);
$("#formAjax").remove();
} else {
//console.log(result);
window.setTimeout(function(){
document.location = "_t_lastpost_"+topicId+"_"+forumId+"?postId="+result.postId;
},1500);
/*returnMessage = '<div id="popup" class="autoClear simple">'
+'Mensagem enviada com sucesso! Clique neste <a href="_t_lastpost_'+topicId+'_'+forumId+'">link</a> para ver sua mensagem'
+'</div>';*/
}
} else {
if(result.nickname_reproved){
document.location = "changenickname.jbb";
} else {
$("#carregando").remove();
for(i = 0; i < result.messages.length; i++){
$("#formAjax").prepend('<div id="popup" class="autoClear error-post">'
+result.messages[i]+'<br/>'
+'</div>');
}
$.scrollTo("#popup",500);
$("#formSubmit").html('<a href="#" class="formSubmit" tabindex="3"><img src="'+baseImages+'/themes/'+desTheme+'/images/pm_send.gif"/></a>');
$(".formSubmit").bind("click",function(e){
formSubmitFunction(e,"post")
});
}
}
}
@ EDIT2:
PostFunctions.insertPost = function(p0, p1, callback) {
DWREngine._execute(PostFunctions._path, 'PostFunctions', 'insertPost', p0, p1, callback);
}
它看起来像你使用jQuery,但实际的'POST'功能都位于'PostFunctions'对象。您需要显示该部分的代码并解释问题的具体内容。 – jeroen
发现它,在主帖子上编辑,问题是:由于提交按钮使用ajax,我无法使用curl发布新消息,我可以使用PHP吗? –
@AndréCardoso,你绝对可以使用cURL。 AJAX没什么特别的......它只是普通的HTTP,就像其他任何东西一样。 – Brad