1
嗨我有這段代碼通過AJAX和文件php提交評論而無需刷新頁面。 是用來工作,但因爲我改變了電腦開發這個應用程序我有問題,代碼從未改變。 現在它要麼崩潰Chrome或沒有達到文件comment.php用AJAX提交評論,不刷新頁面不再工作
這裏是JS代碼
<script src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$("#formcomment").submit(function(){
ctask = this.task.value;
cname = this.usrnm.value;
cmessage = this.comment.value;
submitter = this.submitter;
cty = this.ty.value;
celem = this.elem.value;
cusrcd = this.usrcd.value;
cusrcdauth = this.usrcdauth;
val_recaptcha_challenge_field = this.recaptcha_challenge_field.value;
val_recaptcha_response_field = this.recaptcha_response_field.value;
if(cname=="" || cmessage=="") { $("#errAll").html('<p>Please don\'t leave the requierd fields.</p>'); }
$.post("/comment.php", {task: ctask, usrnm: cname, comment: cmessage, ty: cty, elem: celem, recaptcha_challenge_field:val_recaptcha_challenge_field, recaptcha_response_field:val_recaptcha_response_field, usrcd: cusrcd, usrcdauth: cusrcdauth}, function(data){
if(data=='0') { $("#errAll").html('<p>Please don\'t leave the requierd fields.</p>'); }
else if (data=='1') {$("#errAll").html('<p>The reCAPTCHA wasn\'t entered correctly. Try it again.</p>'); }
else if (data=='2') {$("#errAll").html('<p>Username must contain 6 to 20 characters.</p>'); }
else {
submitter.value="Comment posted";
submitter.disabled=true;
$('#listcom').prepend(data);
$("#errAll").html('');
window.location.hash = "#comments";
}
});
return false;
});
</script>
,並在頁面表單
<form class="well" method="post" id="formcomment">
<input type="hidden" id="ty" name="ty" value="stg" />
<input type="hidden" id="elem" name="elem" value="13" />
<input type="hidden" name="task" id="task" value="addComments" />
<input type="hidden" name="usrcdauth" id="usrcdauth" value="yudtjnisifwndyubleedbtisngvxlj" />
<label>Username</label>
<input value="" type="text" id="usrnm" name="usrnm" maxlength="20" class="span3" />
<input type="hidden" id="usrcd" name="usrcd" value="" />
<label>Message</label>
<textarea id="comment" name="comment" rows="5" cols="150" class="span7"></textarea>
<div style="margin: 15px 0;"><input type="submit" id="submitter" name="submitter" value="Add Comment" class="btn" /></div>
<div id="errAll"></div>
</form>
之前和之後是什麼類型的計算機?你有沒有改變操作系統的風味? Windows到Linux? –
提示:使用Firebug(Chrome或Firefox)或內置的Chrome開發工具 - > JS控制檯來檢測JS錯誤和警告,如404的等。 –
我找不出問題,但我刪除了文件,然後創建一個新的,一切都完美。我不知道爲什麼 – user1225730