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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:41:11+00:00 2026-06-03T00:41:11+00:00

The problem i have is with a simple ajax mail script. I have it

  • 0

The problem i have is with a simple ajax mail script.

I have it working fine like this:

php snippet:

if(mail($to,$subject,$message,$headers)){
echo "success";
}

And back in the ajax code its handled here :

         if($.trim(data) == "success"){
           // do the success stuff
         }else{
           // doo the fail stuff
         }

My concern is that in the jquery code “trim” is not supported in all versions of explorer.
So i would rather have the php return the string “success” already trimmed.
But changing things to what you see below does not work as i expected, and runs the fail function in the ajax..?

Ammended php :

if(mail($to,$subject,$message,$headers)){
$success = trim("success");
echo $success;
}

Ammended Ajax :

     if(data == "success"){
         // do success stuff does not happen anymore
     }else{
         // now it always does fail stuff, so comparison is always false
     }

Why is doing the trimming in the php instead of the ajax letting me down please..?

  • 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-03T00:41:12+00:00Added an answer on June 3, 2026 at 12:41 am

    Your problem is not with the string “success”. Trimming just removes spaces and white-characters (newlines, etc.) from the beginning and ending of a string. And in “success” there is no such thing, so it does nothing. However, if trimming on the JavaScript side works, then your PHP must be producing some whitespace characters, so it appears in the response. But this is not in the code you posted, there is no problem with the work “success”. You have to go through your code and find the source of the newlines/spaces/white characters.

    Usually, the problem is with Unicode BOM marks (look that up and open your PHP files in an editor that can show you if they are present or not) or newlines at the end of a PHP file (remove these).

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

Sidebar

Related Questions

I have a simple Ajax script that works perfectly fine in Chrome, Internet Explorer
I have a simple $.ajax call that returns a response that looks like this:
It looks like a problem which could have simple solution, but I haven't found
Hi I am new to PHP and have a simple problem but I have
I have a simple problem with XML got from database. Now, this XML can
I am trying to make a simple AJAX calling in PHP and have a
I have a simple page that returns an ajax success/error message on submission. The
I have this simple jQuery ajax post to a Pyramid webapp. Ajax call: $.ajax({
I have encountered a unique problem. I am doing a simple ajax call using
I've been working on some simple AJAX functions recently, using MooTools. My problem lies

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.