search
HomeWeb Front-endJS TutorialDetailed explanation of steps to read properties using ajax

This time I will bring you a detailed explanation of the steps for ajax to read properties. What are the precautions for ajax to read properties? The following is a practical case, let's take a look.

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 calls ajax processing code:

$.ajax({
 type:'POST',
 dataType:'json',
 url:'/jeecms/jeecms/ajax/cms/getResourceBundle.do',
 async:false,
 success:function(data){
  jsonData=data.jsI18n;//jsI18n是java返回时赋予的名称
  jsi18n=eval_r('('+jsonData+')');//转化为json对象
  alert("property is "+jsi18n.hello);
 },
 error:function(data){
  alert("error");
 }
});

javaProcessing 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);
}//判断语言类别的,忽视
Set keySet=RESOURCE_BUNDLE.keySet();
//读取资源文件数据拼接成json格式字符串返回
String jsonString = newString();
jsonString+="{";
for(String key:keySet){
 jsonString+='"'+key+'"'+":"+'"'+RESOURCE_BUNDLE.getString(key)+'"'+",";
}
//把字符串赋给返回对象的jsI18n(这里随意)
jsonRoot.put("jsI18n",jsonString.substring(0,jsonString.length()-1)+"}");
return SUCCESS;
}

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to implement partial refresh function with jQuery and ajax

How to use Ajax to implement loop

The above is the detailed content of Detailed explanation of steps to read properties using ajax. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Nginx中404页面怎么配置及AJAX请求返回404页面Nginx中404页面怎么配置及AJAX请求返回404页面May 26, 2023 pm 09:47 PM

404页面基础配置404错误是www网站访问容易出现的错误。最常见的出错提示:404notfound。404错误页的设置对网站seo有很大的影响,而设置不当,比如直接转跳主页等,会被搜索引擎降权拔毛。404页面的目的应该是告诉用户:你所请求的页面是不存在的,同时引导用户浏览网站其他页面而不是关掉窗口离去。搜索引擎通过http状态码来识别网页的状态。当搜索引擎获得了一个错误链接时,网站应该返回404状态码,告诉搜索引擎放弃对该链接的索引。而如果返回200或302状态码,搜索引擎就会为该链接建立索引

Scrapy基于Ajax异步加载实现方法Scrapy基于Ajax异步加载实现方法Jun 22, 2023 pm 11:09 PM

Scrapy是一个开源的Python爬虫框架,它可以快速高效地从网站上获取数据。然而,很多网站采用了Ajax异步加载技术,使得Scrapy无法直接获取数据。本文将介绍基于Ajax异步加载的Scrapy实现方法。一、Ajax异步加载原理Ajax异步加载:在传统的页面加载方式中,浏览器发送请求到服务器后,必须等待服务器返回响应并将页面全部加载完毕才能进行下一步操

在SpringBoot下怎么读取自定义properties配置文件在SpringBoot下怎么读取自定义properties配置文件May 13, 2023 pm 10:43 PM

一、在resource中新建.properties文件在resource目录下新建一个config文件夹,然后新建一个.properties文件放在该文件夹下。如图remote.properties所示二、编写配置文件remote.uploadFilesUrl=/resource/files/remote.uploadPicUrl=/resource/pic/三、新建一个配置类RemoteProperties.java@Configuration@ConfigurationProperties(

如何使用CakePHP中的AJAX?如何使用CakePHP中的AJAX?Jun 04, 2023 pm 08:01 PM

作为一种基于MVC模式的PHP框架,CakePHP已成为许多Web开发人员的首选。它的结构简单,易于扩展,而其中的AJAX技术更是让开发变得更加高效。在本文中,将介绍如何使用CakePHP中的AJAX。什么是AJAX?在介绍如何在CakePHP中使用AJAX之前,我们先来了解一下什么是AJAX。AJAX是“异步JavaScript和XML”的缩写,是指一种在

什么是ajax重构什么是ajax重构Jul 01, 2022 pm 05:12 PM

ajax重构指的是在不改变软件现有功能的基础上,通过调整程序代码改善软件的质量、性能,使其程序的设计模式和架构更合理,提高软件的扩展性和维护性;Ajax的实现主要依赖于XMLHttpRequest对象,由于该对象的实例在处理事件完成后就会被销毁,所以在需要调用它的时候就要重新构建。

jquery ajax报错403怎么办jquery ajax报错403怎么办Nov 30, 2022 am 10:09 AM

jquery ajax报错403是因为前端和服务器的域名不同而触发了防盗链机制,其解决办法:1、打开相应的代码文件;2、通过“public CorsFilter corsFilter() {...}”方法设置允许的域即可。

读取properties文件的6种方式,建议收藏!读取properties文件的6种方式,建议收藏!Aug 15, 2023 pm 04:03 PM

这年头基本上都是使用Spring Boot开发,然后都知道在项目中会有个application.properties配置文件(也有的是application.yaml,反正就是用来保存我们的一些配置信息),通常我们会把一些配置信息写到properties文件中,比如:数据库连接信息、第三方接口信息(密钥、用户名、密码、地址等),连接池、Redis配置信息、各种第三方组件配置信息

SpringBoot怎么实现读取YML,yaml,properties文件SpringBoot怎么实现读取YML,yaml,properties文件May 13, 2023 pm 09:07 PM

yml,yaml,properties三种文件都是用来存放配置的文件,一些静态数据,配置的数据都会存放到里边。但是有的时候我们不仅仅需要存储静态数据,还需要从文件中读取数据出来。这三种文件都放在项目--》src--》main--》resource下边。如果resource里边需要存放其他文件的话,会在resource里边创建一个config包。将配置文件存放其中。1.在项目中新建配置文件,文件存放地址bootstrap.yml是SpringBoot程序的一个配置文件,在项目启动前就会被加载,将数

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft