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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:10:56+00:00 2026-05-17T16:10:56+00:00

This might spund a little bit funny, didn’t even know how to put the

  • 0

This might spund a little bit funny, didn’t even know how to put the title at first. It could be due to long hours of work or I’m just doing something wrong.

I have a file, say comment.php, which contains something similar to:

var params = $('form#myform').serialize();
$.get("/ajax/file.php?"+params, function(data){
    if (data == 'error') {
        $('#message').html('Error');
    } else if (data == 'success') {
        $('#message').html('Success');
    }
});

I checked it with firebug and everything is ok, no JS errors, the file is being called and returns either ‘error’ either ‘success’, but still, in the body of the ajax call data doesn’t match the server response. I then changed

if (data == 'error') {
    $('#message').html('Error');
} else if (data == 'success') {
    $('#message').html('Success');
}

with

if (trim(data) == 'error') {
    $('#message').html('Error');
} else if (data == 'success') {
    $('#message').html('Success');
}

where trim() is a function I wrote that removes any spaces before or after the string. I also tried wit the file being called echoing numbers and making the check with jQuery like:

if (data == 1) {
    $('#message').html('Error');
} else if (data == 'success') {
    $('#message').html('Success');
} 

with no results. If I only alert(data) everything looks fine tough. Both files are on the same domain. My code is exactly as in the example just that I have more if/else conditions and one of them should allways match (it does if I look in firebug). I also tried using a switch statement with no result.

I’ve been using this method for some time now and never had any problems. Ideas?

  • 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-17T16:10:57+00:00Added an answer on May 17, 2026 at 4:10 pm

    The .get() callback callback uses 3 arguments:

    1. the data
    2. the status
    3. the XMLHttpRequest

    So, you’re method should work. Make sure you pay attention to capitalization, punctuation, and whitespace.

    I would try and get more info about data to pinpoint the problem:

    var params = $('form#myform').serialize();
    $.get("/ajax/file.php?"+params, function(data){    
            alert("Type: " + typeof.data +
                  "\nContents: ==>" + data + "<==" +
                  "\nTrim: ==>" + $.trim(data) + "<==");  // get more info
    });
    

    Note that jQuery has a $.trim() function

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

Sidebar

Related Questions

I know this question might sound a little bit crazy, but I tough that
I know this question might sound a little cheesy but this is the first
This might sound like a little bit of a crazy question, but how can
Ok this might sound a little vague from the title, but that's because I
This might sound a bit of an odd question but I know what I
this question might sound a little bit weired... But I will try to explain:
Hi i know the Title might sound a little confusing but im reading in
This might sound a bit confusing at first. But I have a table with
I know this might sound a little silly. but I'm confused as to what
I know that the title might sound a little contradictory, but what I'm asking

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.