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 7755741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:38:25+00:00 2026-06-01T12:38:25+00:00

Background: Using jQuery 1.7 client side PHP server side Using json responses with json_encode

  • 0

Background:

  • Using jQuery 1.7 client side
  • PHP server side
  • Using json responses with json_encode php function
  • The content-type header is correct, any of these works: text/plain,text/x-json,application/json.
  • There’s no errors thrown from my php code
  • Am working on Firefox 11
  • Am using the js console and the other web’s developer tools
  • HTTP/1.1 200 OK

In this Javascript code, the success event is never fired:

$.ajaxSetup({cache:false,
        success:function(d) {
            console.log("ok from setup with data "+d.toSource())
        },
        complete:function(xhr,ts){
            console.log("Ajax finished reponse:"+xhr.responseText)
        },
        error:function(jqXHR, textStatus, errorThrown){
            console.log("Error")
        }
});
$.getJSON("test2.php",{},function(data){
    //some code here
});

When I do it this way, it works:

$.ajaxSetup({cache:false,                
        complete:function(xhr,ts){
            console.log("Ajax completado con:"+xhr.responseText)
        },
        error:function(jqXHR, textStatus, errorThrown){
            console.log("Error")
        }
});
$.getJSON("test2.php",{},
     function(data){
            //some code here
     }).success(function(d){
            console.log("success applied directly, data "+d.toSource())
        }
);

In both cases the complete event is always fired and the error one never.
However, in the second code the success is fired.
Obviously for .get() method it’s the same.

PHP code:

<?php header("Content-Type:application/json;charset=utf-8");
    //or whatever text/x-json text/plain, even text/html, jquery do the dirty job
echo json_encode(array("stat"=>"1")) ?>

My objectives:

  1. I want to fire the same success event to all ajax requests
  2. I want to use the json data returned by the request in my success event, and if it is possible, without convert the raw jqXHR responseText to a json again

The problem is strange, any ideas?


I read all these questions:

  • Ajax success event not working
  • AjaxSetup never execute the success function
  • Does jQuery ajaxSetup method not work with $.get or $.post?
  • $.ajax function's success: not firing

And I’m pretty sure none of them are my problem.

  • 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-01T12:38:26+00:00Added an answer on June 1, 2026 at 12:38 pm

    Take a look at the ajaxSetup documentation: http://api.jquery.com/jQuery.ajaxSetup/

    Note: Global callback functions should be set with their respective
    global Ajax event handler methods—.ajaxStart(), .ajaxStop(),
    .ajaxComplete(), .ajaxError(), .ajaxSuccess(), .ajaxSend()—rather than
    within the options object for $.ajaxSetup().

    I think that’s your problem right there.

    UPDATE

    If you want your ajax handlers to be global for any ajax request on the page, do something like this:

    $(document).ajaxSuccess(function(d){
        console.log("ok from setup with data "+d.toSource());
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following backbone.js client side template: <script id=calleeTemplate type=text/x-jquery-tmpl> <tr style=background-color: ${StatusColour}>
I have added some animation using jquery but it's not working: $('.test-container').click(function(){ $(this).css('background-color', 'rgb(119,
I am trying to change the menuOption background-color on hover using JQuery. All my
I'm using the jquery .css property to add a background myobj.css('background', '#AE0000'); This results
I'm using the jquery tabs plugin and want to have the background a light
I'm using the Tablesorter Jquery plugin to sort a table, but the images background
I am using this code: $('.ui-accordion').bind('accordionchange', function(event, ui) { $(this).next().next().css({'background-image':'images/green-bg.jpg'}); //ui.newHeader // jQuery object,
Background Using JavaScript, I need to sort a large JSON object based on a
I'm using jQuery to change the background image of a button depending on the
I am using Jquery - is there a simple way to change the background

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.