このデータを返すサーバー側のファイルがあります
{
success: true,
m_sName:'smith, james',
m_ShortName:'Jim_S',
m_FirstName:'james',
m_LastName:'smith',
m_Rank:'CONT',
m_Unit:'',
m_Address:'PO Box 241',
m_City:'guthrie',
m_State:'KY',
m_Zip:'42234',
m_Phone:'270-956-3174',
m_Fax:'',
m_Email:'krullwarking@yahoo.com',
m_Title:'',
m_RegnetName:'james.andrew.smith',
m_BirthMonth:'10',
m_UserID:105745,
m_Age:47
}
次に、クライアントに次のようなコードがあります。
var Person = {
//Private members
getXmlRequestObj : function() {
if (window.XMLHttpRequest) {
importHTML2: new XMLHttpRequest();
} else if(window.ActiveXObject) {
importHTML2: new ActiveXObject("Microsoft.XMLHTTP");
} else {
importHTML2: "Your Browser needs an upgrade";
}
},
//Set up the global content retrieval object
//called importHTML
importHTML: new ActiveXObject("Microsoft.XMLHTTP"),
getAjaxData:function(sUrl) {
if (Person.importHTML.readyState == 4 || Person.importHTML.readyState == 0) {
Person.importHTML.open("GET", sUrl, false);// make it wait for the response
Person.importHTML.onreadystatechange = Person.handleDataArrived;
Person.importHTML.send(null);
}
},
//Called when the AJAX response is returned from any operation
//that lists handleContentArrived as its onreadystatechanged event
//for importHTML eg:importHTML.onreadystatechange = handleContentArrived; .
handleDataArrived: function() {
if (Person.importHTML.readyState == 4) {
Person._bar = eval("("+Person.importHTML.responseText+")");
Person._sName = Person._bar.m_sName;
Person._ShortName = Person._bar.m_ShortName;
Person._firstName = Person._bar.m_FirstName;
Person._lastName = Person._bar.m_LastName;
Person._Unit = Person._bar.m_Unit;
Person._securityGroups = Person._bar.m_Rank;
Person._height = '6.0 ft';
Person._weight = '280lbs';
Person._hairColor = 'Brown/gray';
Person._photoURL = 'www.photourl.com';
Person._facebookID = 'Krullwarking@yahoo.com';
Person._emailAddress = Person._bar.m_Email;
Person._phoneNumber = Person._bar.m_Phone;
Person._Fax = Person._bar.m_Fax;
Person._NetworkName = Person._bar.m_RegnetName;
Person._ID = Person._bar.m_UserID;
Person._Address = Person._bar.m_Address;
Person._City = Person._bar.m_City;
Person._State = Person._bar.m_State;
Person._Zip = Person._bar.m_Zip;
Person._Title = Person._bar.m_Title;
}
},
wholeName : function()
{
return this._firstName + ', ' + this._lastName;
},
// constructor
loadPerson : function(ID){
Person._ID = ID;
Person.getAjaxData('getUser.asp?uid='+ID);
},
setFirstName : function(fname) {
Person._firstName = fname;
return true;
},
// add the methods to the prototype so that all of the
// Foo instances can access the private static
getFirstName : function() {
return Person._firstName;
}
}
Student = {
superClass:Person,
sayHello : function(){ alert('hi, I am a student, and my name is '+this.superClass.wholeName());}
}
Student.superClass.loadPerson(105745);
Student.sayHello();
これは正常に機能しますが、xmlHTTPへのActiveX参照のため、IEでのみ機能します。importHTML変数にthis.getXmlRequestObjまたはPerson.getXmlRequestObjを呼び出させようとするたびに、機能しません.....どうすればよいですか?