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

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):
      class Ajax_test extends Controller {
          function Ajax_test()
          function index()
          function process()
              //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");
I am trying to pass
to this view:

<!DOCTYPE html>
&lt;html lang="en"&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; }


$(document).ready(function() {
    // hides the slickbox as soon as the DOM is ready
    // (a little sooner than page load)

    // toggles the slickbox on clicking the noted link
    $('#edit-text').click(function() {
        return false;

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

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

      }, "xml");


        return false;


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

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

<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>


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?

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

mattpointblank is right
remove it and post here how it's going

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.