Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8657547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:32:51+00:00 2026-06-12T15:32:51+00:00

Using PHP Zend Framework 2.0.2, I return JSON data after an AJAX call. Obviously,

  • 0

Using PHP Zend Framework 2.0.2, I return JSON data after an AJAX call. Obviously, Internet Explorer 9 wants to download the data instead of returning it to the calling Javascript method.

Posts like this one and this one say to use Content-Type: text/plain instead of Content-Type: application/json, but how do I do this with ZF2’s JsonModel? I’m new to it…

I imagine I have to set something in the setOptions() array, but what?

public function testJsonAction()
{
   $jsonResponse = new JsonModel(array('success' => false));

   $jsonResponse->setOptions(array(
         // ** Should I put something here? What? **
   ));

   return $jsonResponse;
}

I tried using these:

  $this->getResponse()->getHeaders()->addHeaderLine('Content-Type', 'text/plain');
  $this->getResponse()->getHeaders()->addHeaderLine('Content-Disposition', 'inline; filename="textdata.json"');

but it doesn’t change the HTTP Content-Type in the response headers:

Key                   Value
Response              HTTP/1.1 200 OK
Content-Type          application/json
Server                Microsoft-IIS/7.5
X-Powered-By          PHP/5.3.13
Set-Cookie            ZDEDebuggerPresent=php,phtml,php3; path=/
Content-Disposition   inline; filename="textdata.json"
X-Powered-By          ASP.NET
Date                  Wed, 10 Oct 2012 13:19:42 GMT
Content-Length        17

Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:32:52+00:00Added an answer on June 12, 2026 at 3:32 pm

    Because when \Zend\Mvc\MvcEvent::EVENT_RENDER event happen, the JsonStrategy will change content-type again. Source code is in

    Zend\View\Strategy\JsonStrategy->injectResponse();

    So in order to replace content-type into yours, you need to use EventManager to inject your custom header after JsonStrategy injected.

    try below codes in your controller:

     $this->getServiceLocator()->get('Application')->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function($event){
         $event->getResponse()->getHeaders()->addHeaderLine('Content-Type', 'text/plain');
     }, -10000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PHP and Zend Framework in my application. User can enter some HTML
I've built a search index using the PHP Zend Framework Search (based on Lucene).
I am trying to build a Connect app using PHP and the Zend Framework.
I'm trying to create a Zend Framework project using PHP 5.3.2 and Zend Framework
I'm currently using Zend Framework 2 beta for on PHP 5.4.4 to develop a
I have a PHP MVC application using Zend Framework. As presented in the quickstart,
I am making a PHP image uploader using the Zend Framework which will upload
All, I have a PHP Web application built using Zend Framework and MVC with
I want to write a worker for beanstalkd in php, using a Zend Framework
I'm using the Zend framework to access the YouTube Data API. The function below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.