I am using PHP + CURL to fetch data from a server in one of my actions. I then return the data as json from my action.
My action looks like this
public function executeTest(sfWebRequest $request)
{
$json = $this->getServerResponse(); // fetches data using CURL
$this->getResponse()->setContentType('text/json');
return $this->renderText($json);
}
When the above action is executed, the received json strng is (for example):
{ 'ok': true }1
If I change the last line in the action above to return $this->renderText('foo');
the returned JSON is:
{ 'ok': true }foo
If I change the last line in the action above to return $this->renderText('');
the returned JSON is:
{ 'ok': true }
My question are:
Why is the JSON data from the server being displayed together with the text in my renderText() method?
Where is the '1' appended to the JSON data coming from?
How do I resolve/fix this issue ?
I am running Symfony 1.4.x on Ubuntu
1 Answer 1
From the looks of it, your problem lies in getServerResponse()
. Can't help more without seeing that function.
1 Comment
Explore related questions
See similar questions with these tags.
getServerResponse
function sets the response text and then returns true. This accounts for the1
being appended (rendering true shows as a 1), the string foo and the empty string. All of which are being appended. @OP - You should really getgetServerResponse
toreturn
the response rather than setting it and then returning true.