Welcome Guest, Not a member yet? Register   Sign In
passing a string to a view
#11

I don't want to be presumptive but I looked through the docs. I would NEVER have thought to look at the subtitle "Creating Loops".

But thanks. I'll give it a try.
proof that an old dog can learn new tricks
Reply
#12

No hard feelings from my side. It's just that you generally loop through an array of data and present it as individual sets.
It's easier to look at the code example, and then decide if it's matching your requirements.

If you choose to use the search function together with 'view array' you also get it highlighted, so it's even easier to find.
View - Creating Loops (Search: view array)
Reply
#13

(This post was last modified: 01-28-2018, 06:57 PM by richb201.)

I am still having an issue with this. Here is the controller called 'Configure' code

     //  $string2=json_encode($query->result());           //not using $string2 in this test
       $this->load->view('configure_chart.php.old');


   public function snd_json()  //this gets the request of the ajax in js
{
       $this->output->set_content_type('application/json', 'utf-8');
       $this->output->set_output(file_get_contents("sampleData.json"));
}

and here is the js part of the view

   function drawChart() {
       var jsonData = $.ajax({
           url: "<?php echo base_url(); ?>" + "index.php/Configure/snd_json",
           dataType: "json",
        success: function(jsonData)
        {
        var data = new google.visualization.DataTable(jsonData);
       var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
       // Draw the chart, setting the allowHtml option to true for the tooltips.
      chart.draw(data, {allowHtml: true});
      },
      error: function(jsonData)
      {
      $('info').html('<p>An error has occurred</p>');
      },

            async: false
       }).responseText;

 
I can see that the snd_json is firing and I also see that error: is running. I think the error is due to the jsonData.responseText field that shows up at the client is the html text of a web page instead of the json data I sent over. I keep getting a parser error from AJAX since a regular HTML page is not JSON. I can see that I am sending the right data because I get it with get_output (just to check). I am just fustrated that AJAX is receiving the wrong data in the client.

Any ideas?

I downlowed Fiddler to see exactly what is being sent by my php "callback", snd_json. My message from snd_json appears in Fiddler as a return code 200 which is all is AOK. The content type is text/html. But as you can see in the code above I am setting it to 'application/json'.  It seems that my json data is getting appended onto the html (which my menu header stuff) and then being sent, rather than being sent all on its own. Of course when AJAX gets this HTML+json it gives a parser error because it expects json and the HTML part is not valid JSON. What I don't get is why the HTML is being included at all in what is being sent. It's not there when I look at the buffer prior to sending. But it is there according to Fiddler, when it "hits the cable" (that is just a saying).

I also tried using just echo instead of set output. In this case the Json  is first in the buffer, and then the rest of the HTML page is appended onto the end. Same issue with parsererror.
proof that an old dog can learn new tricks
Reply
#14

well I think I figured it out. I am using something called Simplicity Codeignitor which is a template which creates a menu that I use in my app.
I put this line into my php callback

$this->output->unset_template(); //unset the simplicity

And now the php comes though fine. It is still complaining, now about not having a string in the first column, but at least I can handle that!
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB