2009-08-14 6 views
1

ポスト中に即時ダイアログボックスを表示する方法はありますか?
はここJavaScriptコードjquery Ajax/MVCポストの実行中に即座に「上」に保つ

$('#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; 
    } 

後I [はい]をクリックしたときに「あなたは、あなたが投稿してもよろしいですか?」即興ダイアログが表示されます...消えます...どのように表示されたままにすることができますか?

答えて

1

OKは動作しました...私は即興プラグインとjQueryに本当に感銘を受けました! 私は仕事にこれを取得するために、異なるやったことの2つは

async: false, 
にAJAX呼び出しを設定するために、2つの

return false; 

STATE0ブロックの下に文と...

を追加しました

ここに新しい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; 
} 
関連する問題