Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

58
Vistas
How to integrate Php array to Javascript Using Ajax

I am working on ajax and php,I want to use Php array in javascript,But right not unable to integrate Php array to javascript, Here is my Controller code where i am getting Php array as json(Using Json encode)

function GetFollowingCoinUsers()
        {
            $CoinId=$_POST['coin_id'];
            $result = $this->M_main->GetAllCoinFollower($CoinId);
            $UserId=array();
            foreach($result as $res)
            {
                $UserId[]=$res['UserId'];
            }
            echo json_encode($UserId);
        }

Above code give me result in following way

["463","500","505"]

And i am trying to use this array in Javascript/Ajax Response

$.ajax({
            type: "post",
            url:'<?php echo base_url();?>Main/GetFollowingCoinUsers',
            data: {coin_id:coin_id},
            success: function (datan) {
                    var cars = datan;
                    let text = "";
                    for (let i = 0; i < cars.length; i++) {
                      text += cars[i] + "<br>";
                    }
                    alert(text);
                    
            }
        });
7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can try this:

yourArray = [];

JSON.parse(yourArray.replace(/&quot;/g,'"'));
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos