Welcome Guest, Not a member yet? Register   Sign In
jQuery not getting my response
#1

[eluser]Unknown[/eluser]
I have the following view
Code:
<?php
$this->output
    ->set_content_type('application/json')
    ->set_output(json_encode(array('foo' => 'bar')));
?>

When I access the controller that points to the view, I get my json object.

However, when I run this javascript on the page, I get ResponseText = "", status = 0, textStatus = "error" in the jqXHR object.
Code:
$.ajax('http://localhost/bh/index.php/ajax/test',
{
data: {'input' : 'hi'},
type:'post',
complete: function (data){
  debugger;
}
})();

I'm not sure if there's a problem with jQuery or CI.

Here's the raw response that Fiddler is catching:

Code:
HTTP/1.1 200 OK
Date: Sat, 10 Mar 2012 02:55:11 GMT
Server: Apache/2.2.16 (Win32) mod_ssl/2.2.16 OpenSSL/0.9.8o
X-Powered-By: PHP/5.3.5 ZendServer
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json

d
{"foo":"bar"}
0

Thanks for the help.
#2

[eluser]Aken[/eluser]
Set the content type and output directly from the controller if you're going to do it that way - no need for a view. Also tell your ajax function to look for a json response.
#3

[eluser]Unknown[/eluser]
[quote author="Aken" date="1331351438"]Set the content type and output directly from the controller if you're going to do it that way - no need for a view. Also tell your ajax function to look for a json response.[/quote]

I did that and there's no change in the behavior.




Theme © iAndrew 2016 - Forum software by © MyBB