0

I am using codeigniter in my application and have a jquery post function that works perfectly.

$.post('getticketstacktype', {ticketnumber:ticketnumber},function(result) {
alert(result);
}

I am then using the exact same post function on another edit page. this page is prepopulated with PHP and works correctly.

I use the same post to call my controller, I have checked that ticketnumber value is correct

$.post('getticketstacktype', {ticketnumber:ticketnumber},function(result) {
alert(result);
}

the controller function it calls is:

function getticketstacktype(){    
    if (isset($_POST['ticketnumber'])){
        $ticketnumber = $_POST['ticketnumber'];            
        $data = $this->wos_model->getticketstacktype($ticketnumber);
        $this->output->set_content_type('application/json')->set_output(json_encode($data));
        }
    }

now where this works correctly the result is '7' but instead, on my edit page it is returning my entire view page rendered: so <html><head>......</html> hundereds of lines)

I cant figure out my why my entire page is being returned as a result to a jquery post when it is working in another view.

I have also verified that the post information from both views is the same with firebug.

Any advice? Thanks as always.

tereško
  • 58,060
  • 25
  • 98
  • 150
Smudger
  • 10,451
  • 29
  • 104
  • 179

2 Answers2

1

This usually happens when a fatal error occurred in the backend. When a fatal error occurs on PHP, it constructs a page to displays some error message contained within a box. jQuery tries to interpret to a meaningful data but it fails. And if you see this response in Firebug or Google Chrome Dev tool you can actually see that the page can be rendered.

  1. Use either Firebug or Google Chrome Dev tool to track down the result sent back from the server
  2. Make sure there is no error in your backend side
Beakal
  • 134
  • 1
  • 4
  • 15
  • Thanks, I understand what you mean as you can normally see the php error that is failing but that is local to the function or model being called. this is rendering the current page from where the call was made. – Smudger Apr 17 '14 at 08:56
  • This weird, can you make sure that the controller is not redirecting the request to the current page? – Beakal Apr 20 '14 at 06:25
0

I think you need this:

In your header define in a script tag:

var base_url = '<?php echo base_url() ?>'; //here we keep the base url in a variable to use in our js files

Then include the js file below the above line which is calling your ajax, so we can access the above variable.

Now your ajax function needs to be changed like this:

$.post(base_url+'controller_name/getticketstacktype/', {ticketnumber:ticketnumber},function(result) { //here if you see the absolute path to the funciton is given
    alert(result);
}

You also need to check your firebug's net panel and console for any errors if you got. best of luck. :D

Nil'z
  • 7,487
  • 1
  • 18
  • 28