保持即兴的“向上"状态.在执行jQuery Ajax/MVC帖子时

编程入门 行业动态 更新时间:2024-10-09 18:18:43
本文介绍了保持即兴的“向上"状态.在执行jQuery Ajax/MVC帖子时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种方法可以在发布过程中保持即兴对话框的显示? 这是JavaScript代码

Is there a way to keep the impromptu dialog box displayed during a post? Here's the javascript code

$('#linkPostTest').click(function() { openprompt(); }); function openprompt() { var temp = { state0: { html: 'Are you sure you want to post?<br />', buttons: { Yes: true, No: false }, focus: 1, submit: function(v, m, f) { if (v) { var form = $('frmPostTest'); $.ajax( { type: 'POST', url: '/Path/TestPost', data: form.serialize(), success: function(data) { // I realize I could check "data" // for true...just have not // implemented that yet.... $.prompt.goToState('state1'); //$.prompt('Test was successful!'); }, error: function() { $.prompt.goToState('state2'); //$.prompt('Test was not successful.'); } } ); return true; } else { //$.prompt.goToState('state1'); //go forward return false; } } }, state1: { html: 'Test was successful!', buttons: { Close: 0 }, focus: 0, submit: function(v, m, f) { if (v === 0) { $.prompt.close(); } } }, state2: { html: 'Test was not successful.<br />', buttons: { Close: 0 }, submit: function(v, m, f) { if (v === 0) { $.prompt.close(); } } } }; $.prompt(temp); }

控制器执行此操作

[AcceptVerbs(HttpVerbs.Post)] public bool TestPost() { // runs some code that saves some data... // this works fine bool updated = functionThatSavesCode(); return updated; }

在确定要发布吗?"时,单击是"后.即兴对话框显示...它消失...如何使其保持显示状态?

After I click Yes when the 'Are you sure you want to post?' impromptu dialog is displayed... it disappears...How can I make it stay displayed?

推荐答案

确定可以使用...即兴插件和jQuery给我留下了深刻的印象! 为了使它起作用,我做了不同的两件事是将两者相加

OK got it to work...I'm really impressed with the impromptu plug-in and jQuery! Two of the things I did differently to get this to work was to add the two

return false;

state0块下的语句和...

statements under the state0 block and...

将ajax调用设置为

async: false,

这是新的javascript:

Here's the new javascript:

$('#linkTestPost').click(function() { TestPost(); }); function TestPost() { var temp = { state0: { html: 'Are you sure you want to post?<br />', buttons: { Yes: true, No: false }, focus: 1, submit: function(v, m, f) { if (v) { if (PostView() === true) { $.prompt.goToState('state1'); // the line below was missing from my original attempt return false; } else { $.prompt.goToState('state2'); // the line below was missing from my original attempt return false; } } else { return false; } } }, state1: { html: 'Test Post was successful!', buttons: { Close: 0 }, focus: 0, submit: function(v, m, f) { if (v === 0) { $.prompt.close(); } } }, state2: { html: 'Test Post was not successful', buttons: { Close: 0 }, submit: function(v, m, f) { if (v === 0) { $.prompt.close(); } } } }; $.prompt(temp); } function PostView() { var form = $('frmTestPost'); var postSuccess = new Boolean(); $.ajax( { type: 'POST', url: '/Path/TestPost', data: form.serialize(), // the line below was missing from my original attempt async: false, success: function(data) { postSuccess = true; }, error: function() { postSuccess = false; } }); return postSuccess; }

更多推荐

保持即兴的“向上"状态.在执行jQuery Ajax/MVC帖子时

本文发布于:2023-10-10 18:35:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479393.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   帖子   quot   jQuery   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!