How can I get the specified input value from an ajax request callback data?
$('#action .add').click(function () {
var form = getCreateUserForm(); // GET THE FORM TO CREATE USER
console.log(form);
$('#user_dialog').html(form);
$('#user_dialog').dialog({
modal: true,
width: 700,
height: 600,
resizable: false,
//draggable: false,
title: '<h3>' + ???? + '</h3>', // HERE! HOW TO GET THE INPUT VALUE
open: function (e, ui) {
In my view, I have this
@Html.Hidden(@Localization.CreateUser, null, new { id = "title" })
The data is actually inside the form variable.
how could I get the localization name from the form variable?
or is there any way to handle such situation? am I on the right track?
EDIT
html:
<div id="user_dialog" hidden></div>
Try to get the form:
function getCreateUserForm() {
if (formCreateUser == null) {
$.ajax({
url: '@Url.Action("Create", "User")',
async: false,
success: function (data) {
formCreateUser = data;
}
});
}
return formCreateUser;
}
The dialog has not been opened yet, I could not refer to it using $(‘#title’)
MY SOLUTION
I found the HTML generated by @Html.Hidden is like
<input id="title" name="Create User" type="hidden" value="">
instead of using $('#title').val(), i change it to $('#title').attr('name').
now it works!
1 Answer