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

  • Home
  • SEARCH
  • 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 6375653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:38:37+00:00 2026-05-25T01:38:37+00:00

I have a simple ajax query to a file which basically returns in JSON

  • 0

I have a simple ajax query to a file which basically returns in JSON error or success.

ie:

{"error":"1"}{"error_msg":" Invalid Expiry Date. Your credit card has not been billed for this transaction."}

The issue however is that even though I’m getting this json data return from my ajax post, I can’t seem to access the data at all.

My jquery looks something like this:

     $.ajax({
          type: 'POST',
          url: 'process_sale.php',
          data: $(this).serialize(), 
          cache: false,
          dataType: 'json',
          success: function(data) {

            if(data['success']=='1'){

                alert('hi');

                $('#feedback').html('<strong>Congratulations</strong');

            }

            if(data['error']=='1') {

                alert('hi');

                $('#feedback').html(data['error_msg']);


            }

                   // this following alert does nothing, because its empty even if the json 
                   // returns what I pasted above example result.

                   alert(data['error'] + ' ' + data['success']);

          }
        });

None of the alerts will do anything.

Am I missing something really obvious here? I can’t seem to wrap my head around why this isn’t working as it seems to be fairly identical to other code I have working.

  • 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-05-25T01:38:37+00:00Added an answer on May 25, 2026 at 1:38 am

    You’re trying to parse invalid JSON — you have two adjacent JSON objects in your example. You need to either place them in an array, or make them one object if you want JS to understand them:

    // You want this:
    {"error":"1", // note , not {}
     "error_msg":" Invalid Expiry Date. "+
                  "Your credit card has not been billed for this transaction."}
    
    // or this (notice the `,` and the `[`, and `]`)
    [{"error":"1"},{"error_msg":" Invalid Expiry Date. Your credit card has not been billed for this transaction."}]
    

    Based on the rest of your code, I would wager that the first one will meet your needs better. You’re probably going to prefer to access the error message data[‘error’] and not data[0][‘error’]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple jquery/ajax request to the server which returns the structure and
I'm trying to make a very simple query: $.ajax({ url: ajaxfunc.php, dataType: 'json', success:
I have written a simple jQuery.ajax function which loads a user control from the
I had a realtivley simple ajax application, which I have broken up to be
I have an ajax form in asp.net mvc which is as simple as this:
I have a simple ajax call inside a javascript function to a php file,
I'm doing a simple ajax query which retrieves a variable-length list of values as
I used to have a simple ajax that helped me take all items from
I have seen simple example Ajax source codes in many online tutorials. What I
I have a simple jsp/servlet application and I want to add AJAX feature to

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.