0
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;
}

我在文本框中有价值,但模型的属性仍然为空。

4

1 回答 1

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();                    

然后你有数据

于 2013-10-28T18:32:42.233 回答