function getData()
{
var data = new PostData(DataModel);
processAjaxRequest('/Home/List', 'Post', 'fetchComplete', data);
}
var DataModel =
{
"AccountName": document.getElementById("Account").value,
"AccountKey": document.getElementById("AccountKey").value,
"Id": document.getElementById("Id").value,
"DateTime": document.getElementById("DateTime").value
}
function processAjaxRequest(urlToProcess, httpMethod, successCallback, postData) {
var dataToPost = '';
if (typeof postData != 'undefined') {
dataToPost = postData.DataToPost;
}
$.ajax({
url: urlToProcess,
type: httpMethod,
data: dataToPost,
success: function (data, status) {
var fn = window[successCallback];
fn(data);
},
error: function (xhr, desc, err) {
processAjaxError(xhr, desc, err);
},
});
}
var PostData = function (dataToPost)
{
this.DataToPost = dataToPost;
}
我在文本框中有价值,但模型的属性仍为空。
答案 0 :(得分:0)
var PostData =(function() {
this.DataToPost = "";
PostData.prototpye = {
setData: function(dataToPost) {
this.DataToPost = dataToPost;
},
getData: function() {
return this.DataToPost;
}
}
return PostData;
})();
然后您可以按如下方式设置和获取数据:
var myNewPostData = new PostData();
myNewPostData.setData(someData);
myNewPostData.getData();
然后你有数据