This article gives an example of how Ajax reads properties resource file data. Share to everyone for your reference. The implementation methods are as follows:
The contents of the properties resource file are as follows:
HELLO=ENGLISHWW
name=english ZK
Emailempty=field cannot be empty!
Emailinvalid=invalid Email address!
JS invokes Ajax processing code:
$.ajax ({
type: ' POST ',
dataType: ' json ',
URL: '/jeecms/jeecms/ajax/cms/getresourcebundle.do '
, Async:false,
success:function (data) {
jsondata=data.jsi18n;//jsi18n is the name given when Java returns
Jsi18n=eval_r (' (' +jsondata+ ');//Convert to JSON object
alert ("property is" +jsi18n.hello);
},
error:function (data) {
Alert ("error");
}
);
Java Processing file Getresourcebundle.do code:
Publicstring Getresourcebundle () {
resourcebundle resource_bundle;
if (contextpvd.getsessionattr ("Glanguage")!=null&&contextpvd.getsessionattr ("GLanguage"). Equals ("1")) {
resource_bundle=resourcebundle.getbundle ("jsi18n", locale.english);
} else{
resource_bundle =resourcebundle.getbundle ("jsi18n", Locale.china);
To judge the language category, ignore
Set keyset=resource_bundle.keyset ();
Read resource file data concatenation into JSON format string returns
string jsonstring = NewString ();
jsonstring+= "{";
for (String key:keyset) {
jsonstring+= ' "' +key+ '" ' + ": ' + '" ' +resource_bundle.getstring (Key) + ' "' + ',";
}
Assign the string to the return object's jsi18n (here at random)
jsonroot.put ("jsi18n", Jsonstring.substring (0,jsonstring.length ()-1) + "}");
return SUCCESS;
}
Note: JS request succeeds, if other JS also want to use to read out content, then assign the return value to a global variable.
I hope this article will help you with your AJAX programming.