必承其重 | 欲带皇冠 2016-03-24 12:45 采纳率: 0%
浏览 24

解决语言变化

I want to know about how to retrieve data from map.

I have three button.

Register, Update and Delete from Jsp page.

There are two JSP. First.jsp and Second.jsp.

I included first.jsp in second.jsp.aaa

The buttons are in second.jsp.

At First.jsp.

I have combobox for language change. It must be change language only when click button.

There are two language English and Japanese.

I send API class using ajax according to language id. If id=1(Japanese) and id=2(English).

I Wrote ajax api inside of combobox change function. Below is my code.

 $.ajax({
        url : 'aa/idsend',
        cache : false,
        type : 'GET',
        dataType : 'json',
        contentType : 'application/json; charset=utf-8',
        data : "lid="+select,
              success: function(data) {
               },
            }); 

I receive data from server the following format.

{data = Object {1: "Would you like to register?", 2: "Would you like to update?", 3: "Would you like to delete?"}

Above data are come from database. If I add new data into database the id become 4:"something have".

I want to know how to retrieve these data according button click event. If click register button I want to take register sentence only. The other is also like that.

  • 写回答

1条回答 默认 最新

  • 程序go 2016-03-24 14:11
    关注

    It could be GET method also, but i prefer POST.

    function ajaxRequest(dataObj, cbFunc) {
        $.ajax({
            method: 'POST',
            url: 'aa/idsend',
            data: dataObj
        }).done(function(dataFromServer) {
            cbFunc(dataFromServer);
        });
    }
    
    function useData(dataFS) {
        //do something with data from server dataFS
    }
    
    function getCurrentLanguage() {
      var cL = 'en';//default language
      //some code to get language from checkboxes
      return cL
    }
    
    $('.button').on('click', function(e) {
        var id = $(this).attr('id'),
            jsonData = {},
            curLang = getCurrentLanguage();
    
        switch (id) {
            case 'register' :
                jsonData = {req: 'register', lang: curLang};
                break;
            case 'update' :
                jsonData = {req: 'update', lang: curLang};
                break;
            case 'delete' :
                jsonData = {req: 'delete', lang: curLang};
                break;
            default:
                break;
        }
    
        ajaxRequest(jsonData, useData);
    });
    

    Then in the aa/idsend serverside script you can prepare data to send according to req POST variable received. Now you even don't need to send back questions like 'Would you like to register?'. Instead you can do action according to req value and send back information about the operation - Success! or Fail!

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。