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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:57:26+00:00 2026-06-01T09:57:26+00:00

I use ajax to run MySQL query and echo json_encode result, so that I

  • 0

I use ajax to run MySQL query and echo json_encode result, so that I can get a JSON object:

$.ajax({
    url: phpUrl,
    data: command,
    dataType: 'json',
    async: true,
    success: function(jsonData) {
        //XXX
    }

The JSON object should be like: {cols: [XXXX], rows: [XXXX]}.

Sometimes there is error msg from MySQL query, so the returned JSON object is not valid. How can I determine if the returned JSON object is valid or not?

edit

In http://api.jquery.com/jQuery.ajax/, it says “the JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown”. How to handle the parse error?

  • 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-01T09:57:27+00:00Added an answer on June 1, 2026 at 9:57 am

    Something like this should work:

    $.ajax({
        url: phpUrl,
        data: command,
        dataType: 'json',
        async: true,
        success: function(jsonData) {
            //XXX
        },
        error:function(xhr,err){
            if (err=='parsererror') alert('invalid json');
        }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to run an ajax query using jquery. If I use
I need to reverse result from mysql query, but i cannot use ORDER BY
I use Ajax to kick off a PHP script that can take a few
How can I use AJAX to run a PHP file when the page is
I am writing code that will use AJAX requests to get some HTML code
I am trying to use .ajax() to post a People object to a MVC2
I have many forms that use AJAX (w/ jQuery) for validation and data submission.
While debugging jQuery apps that use AJAX, I often have the need to see
I am using php mysql. First on form submission I run query on mysql
I have come across a website that appears to use Ajax but does not

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.