2011-12-08 22 views
0

我有以下的AJAX連載:序列化的Ajax需要獲得價值

$.ajax({ 
     type: "POST", 
     url: $form.attr('action'), 
     data: $form.serialize(), 
     error: function (xhr, status, error) { 
      ConfirmDialog('The page save failed.'); 
      }, 
     success: function (response) { 
    // need to retrieve an output value from the controller here 

    } 
}); 

當它做了後,我做的到一個ActionResult方法。如何從的ActionResult傳遞一個值,這樣我可以得到它時,它是成功的值(在那裏說成功:函數(響應)

回答

0

輸出是在響應

success: function(response) { 
    alert(response); 
} 
+0

感謝您的回覆,我如何從控制器傳遞一個值,並且它會像response.IDVal = ..在響應中的東西 –

+0

哦,我很抱歉,我不知道如何json編碼在php中我們只是'echo json_encode(array('id'=>'value'))'然後在javascript中你可以通過'response.id'來訪問它 –