• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot pass XML from controller to JQuery to save my life!

#1
[eluser]Unknown[/eluser]
Everything is working fine on the database end. I just cannot display a CSS element based on content sent from the controller.

I have the following controller (please ignore comments - It works with JSON):
Code:
<?php
      
      class Ajax_test extends Controller {
      
          function Ajax_test()
          {
              parent::Controller();
          }
          
          function index()
          {
              $this->load->view('ajax_test_view');
          }
      
          function process()
          {
              
              $this->load->model('Ajax_test_model');
              //inside your system/application/models folder, create a model based on the procedure
              //outlined in the CI documentation
              $record = $this->Ajax_test_model->insert_entry();
              //get the record from the database
              //$array = array('result' => 'cool dude');
              //echo json_encode($array);
              echo '<test>bogus</test>';
              $this->output->set_header("Content-type: text/xml");
              
          }
      }
      ?&gt;
I am trying to pass
Code:
<test>bogus</test>
to this view:

Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
   &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

  
    &lt;style type="text/css"&gt;
    a.test { font-weight: bold; }
&lt;/style&gt;

   [removed][removed]
   [removed]

$(document).ready(function() {
    // hides the slickbox as soon as the DOM is ready
    // (a little sooner than page load)
    $('#edit').hide();
    $('#add-text').hide();
    $('#submitted').html("");
    $('#submitted').hide();
    $('#loader').hide();

    // toggles the slickbox on clicking the noted link
    $('#edit-text').click(function() {
        $('#edit').show();
        $('#field').hide();
        $('#add-text').show();
        $('#edit-text').hide();
        $('#submitted').html("");
        $('#submitted').hide();
        return false;
    });

    // toggles the slickbox on clicking the noted link
    $('#add-text').click(function() {
        $('#edit').hide();
        $('#add-text').hide();
        $('#loader').show();
        var dataString = 'name='+ $("#name").val();

        $.post("/ajax_test/process", dataString,  function(xml) {

        $('#submitted').html($("test",xml).text());
         $('#loader').hide();
             $('#field').show();
             $('#edit-text').show();
      }, "xml");

        $('#submitted').show();

        return false;
    });

});
   [removed]
&lt;/head&gt;
&lt;body&gt;

<span id="field">
This is the text to replace.
</span>

<span id="edit">
&lt;input type="text" name="name" id="name" size="25" value="This is the text to replace."&gt;
</span>

<a href="#" id="edit-text">edit</a>
<a href="#" id="add-text">add</a>
<span id="submitted"> </span>
<span id="loader"> <img src="/home/laborlaw/images/ajax-loader.gif" />  </span>


&lt;/body&gt;
&lt;/html&gt;

for some reason, when I click add, the entry is added to the DB, but the id="submitted" will not display the message from the XML passed from the controller.

Can anyone help me on this?

#2
[eluser]mattpointblank[/eluser]
Putting your XML before this line: $this->output->set_header("Content-type: text/xml") is probably not helping.

#3
[eluser]boltoncole[/eluser]
mattpointblank is right
remove it and post here how it's going

#4
[eluser]Unknown[/eluser]
moving $this->output->set_header(“Content-type: text/xml”) after has no effect. . .
I was able to pass XML when I wasn't using codeigniter, but just inline PHP.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.