我正在構建一個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