Skip to main content

Bug Tracker

Side navigation

#11006 closed bug (invalid)

Opened December 13, 2011 09:12AM UTC

Closed December 13, 2011 12:55PM UTC

Last modified March 14, 2012 04:58PM UTC

$.ajax() dont trigger success-Method when PHP-Header is set

Reported by: Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


when I request a PHP site with header "application/javascript", the "success" method get not triggered (only the "error" method).

The server return code 200

HTML Code:

<!DOCTYPE html>

<html lang="de">
<!-- meta -->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />

<!-- javascript -->
<script type="text/javascript" src=""></script>


function withHeader()
    test({header: 1});

function withoutHeader()
    test({header: 0});

function test(data)
        url: 'test.php',
        type: 'GET',
        data: data,
        error: function(result)
           console.debug('readyState: ' + result.readyState);
           console.debug('status: ' + result.status);
        success: function(result)



<button type="button" onclick="withHeader();">test withHeader</button>
<button type="button" onclick="withoutHeader();">test withoutHeader</button>

<p id="output"></p>


PHP Code (needs server):

if (isset($_GET['header']) && $_GET['header'])
    header('Content-Type: application/javascript');

echo '{varname: varvalue}';



Attachments (0)
Change History (5)

Changed December 13, 2011 10:44AM UTC by sindresorhus comment:1

owner: →
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: Open the link and click to "Fork" (in the top menu) to get started.

Changed December 13, 2011 12:55PM UTC by jaubourg comment:2

resolution: → invalid
status: pendingclosed

What you're echoing is not valid javascript, it's not even valid json.

Please use our forum or the #jquery channel on for this kind of support questions.

Changed December 19, 2011 09:45PM UTC by anonymous comment:3

This issue should not have been closed. His code is an example only. I am experiencing this same issue when attempting to use $.ajax to retrieve JSON returned by PHP. The success handler fires fine when using jQuery 1.6.3, but an upgrade to 1.7.1 breaks it.

Changed March 14, 2012 04:43PM UTC by comment:4

That's real bug, in earlier versions all work fine. JSON response absolute valid.

Changed March 14, 2012 04:58PM UTC by comment:5

Replying to [comment:4 busy-v@…]:

That's real bug, in earlier versions all work fine. JSON response absolute valid.

OOhhh, sorry. Trouble was in incorrect ContentType header. For json output header must be application/json but not text/htm or text/javascript.