1 回答

TA貢獻(xiàn)55條經(jīng)驗(yàn) 獲得超37個(gè)贊
說(shuō)說(shuō)思路吧:無(wú)刷新上傳文件,利用ajax技術(shù),將文件通過(guò)post的形式傳給后臺(tái),在success的回調(diào)函數(shù)中對(duì)當(dāng)前進(jìn)行刷新就行!
這里有個(gè)表單的樣例,都是一樣的,你看看:
$(function(){
? ?$('#send').click(function(){
? ? ? ? $.ajax({
? ? ? ? ? ? type: "POST",
? ? ? ? ? ? url: "test/demo",
? ? ? ? ? ? data: {username:$("#username").val(), content:$("#content").val()},
? ? ? ? ? ? dataType: "json",
? ? ? ? ? ? success: function(data){
? ? ? ? ? ? ? ? ? ? ? ? $('#resText').empty(); ? //清空resText里面的所有內(nèi)容
? ? ? ? ? ? ? ? ? ? ? ? var html = '';
? ? ? ? ? ? ? ? ? ? ? ? $.each(data, function(commentIndex, comment){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? html += '<div class="comment"><h6>' + comment['username'] ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? + ':</h6><p class="para"' + comment['content'] ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? + '</p></div>';
? ? ? ? ? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? ? ? ? ? $('#resText').html(html);
? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? });
? ?});
});
這樣,只要成功后就會(huì)無(wú)刷新的更新頁(yè)面!
當(dāng)然這個(gè)用了jquery,如果想用純javascript,可以百度一下,demo一大堆!思路都是一樣的
添加回答
舉報(bào)