ajax請求里面的success和error里面的layer.msg,status: "parsererror",刷新父界面,碰到的一些問題


一開始ajax執行了請求,並且也更新成功了,但是沒有走success,報status: "parsererror"錯,后來發現是dataType:‘json’要注釋掉,因為我controller返回的不是對象,是字符串

 $.ajax({ type: 'POST', url: '/updateagent', data:JSON.stringify(data), /*dataType: 'json',*/ contentType:"application/json", success: function(result){ layer.msg('修改成功!',{icon:1,time:1000, end:function () { var index = parent.layer.getFrameIndex(window.name); parent.$('.btn-refresh').click(); parent.layer.close(index); } }); }, error:function() { layer.msg('error!',{icon:1,time:1000, end:function () { var index = parent.layer.getFrameIndex(window.name); parent.$('.btn-refresh').click(); parent.layer.close(index); } }); } });

還有一個問題是layer.msg沒有執行,ajax是異步的,我一開始把parten.layer.close();放在ajax后面了,layer.msg和layer.close()一起執行了,解決方法是把layer.close(),放到layer.msg里面的end:function()里面
刷新關閉彈窗后,刷新界面。我一開始把刷新,window.parent.location.reload();寫在上面的關閉彈窗后,不知道為啥一直不執行,后來在layer.open()里面end:funtion()刷,可行了。


function
member_add(title,url,w,h){ layer_show_add(title,url,w,h); } function layer_show_add(title,url,w,h){ if (title == null || title == '') { title=false; }; if (url == null || url == '') { url="404.html"; }; if (w == null || w == '') { w=800; }; if (h == null || h == '') { h=($(window).height() - 50); }; layer.open({ type: 2, area: [w+'px', h +'px'], fix: false, //不固定 maxmin: true, shade:0.4, title: title, content: url, end:function () { window.location.reload(); } }); }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM