Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#11006 closed bug (invalid)

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

Reported by: timohuber@… Owned by: timohuber@…
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="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></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}';

greets Timo

Change History (5)

comment:1 Changed 9 years ago by sindresorhus

Owner: set to timohuber@…
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: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 9 years ago by jaubourg

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 irc.freenode.net for this kind of support questions.

comment:3 Changed 9 years ago by anonymous

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.

comment:4 Changed 9 years ago by busy-v@…

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

comment:5 in reply to:  4 Changed 9 years ago by busy-v@…

Replying to 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.

Note: See TracTickets for help on using tickets.