Search code examples
phpmysqlajaxgetjson

Convert Ajax value to Another State


I have spent hours looking for help with returning to another text ini script from json encode. I have a Json_Encode output with value

[
{"JumStatus":3,"status_ppid":"1"},
{"JumStatus":4,"status_ppid":"2"},
{"JumStatus":1,"status_ppid":"3"},
{"JumStatus":1,"status_ppid":"6"}
]

url: "_DEFINE_GET/_GetData.php",
        method: "GET",
        success: function(data) {
            console.log(data);

            var sta = [];
            var jum = [];
            for(var i in data) {
                sta.push(data[i].status_ppid);
                jum.push(data[i].JumStatus);
            }
         var chartdata = {
                labels: sta,
                datasets: [{
                    backgroundColor: [
                        "#2ecc71",
                        "#f1c40f",
                        "#3498db",
                        "#ff5722",
                        "#34495e",
                        '#009688',
                        "#e91e63"
                    ],
                    hoverBackgroundColor: [
                        'rgba(0,255,0,0.3)',
                        'rgba(255,255,0,0.3)',
                        'rgba(0,0,255,0.3)',
                        'rgba(255,0,0,0.3)',
                        'rgba(192,192,192,0.6)',
                        'rgba(42,176,99,0.63)',
                        'rgba(255,0,0,0.3)',
                    ],
                    data: jum,
                }]
            }; 

And my label in labels: sta, is output [1,2,3,6]

But i want to convert that output to another state when in php we use

if      ($status_ppid=="1" ) { $status_ppid=="Application"; }
elseif  ($status_ppid=="2" ) { $status_ppid=="Proccess"; }
elseif  ($status_ppid=="3" ) { $status_ppid=="Staff Validation"; }
elseif  ($status_ppid=="4" ) { $status_ppid=="Analys Validation"; }
elseif  ($status_ppid=="5" ) { $status_ppid=="Manager Validation"; }
elseif  ($status_ppid=="6" ) { $status_ppid=="Done"; }

And my question how to convert like that in Javascript ajax like in PHP?
My Expected value is after change the value but i dont know how to change the value ini script
label is output ['Application','Proccess,Staff','Validation','Done']
Need Help master I am beginner in php


Solution

  • I think you should create method for convert status like this

    function convertStatus(id) {
       var status = "";  
       if (id == '1') {
          status = "Application";
       } else if (id == '2') {
          status = "Proccess";
       } else if (id == '3'){ 
          status = "Staff Validation";
       } else if (id == '4'){ 
          status = "Analys Validation";
       } else if (id == '5'){ 
          status = "Manager Validation";
       } else if (id == '6'){ 
          status = "Done";
       }
       return status;
    }
    

    And you call the method before push to array

    sta.push(convertStatus(data[i].status_ppid));