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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:47:41+00:00 2026-06-05T19:47:41+00:00

I am using JQUERY .ajax() to send serialized form data to MySQL using PHP.

  • 0

I am using JQUERY .ajax() to send serialized form data to MySQL using PHP. The backend PHP being called will return a message if there was an issue processing the data. My Javascript function then checks for a message being returned before deciding what to do next. If the message length is ‘0’, then the post was successful and it can carry on. If the message length > ‘0’, then an error must have occured in the form processing, and it traps there to deal with it. However, when testing, I found that a successful processing of my form data, returned a message of size 13, even though the message itself was blank.

The javascript function I used is below. I have modified it to test for a message length of more than 13 characters, and this is working fine now. I’ am just curious as to why a blank response is 13 characters in length. Ignore the complicated .load() statements, they just return the user to a different page depending on whether an error message was detected or not.

$("button#update").click(function() {
    var cat = $("select#cat_select").val();
    var dataString = $("form#project_update").serialize();
      $.ajax({
      type: "POST",
      url: "process.php",
      data: dataString,
      dataType: 'text', 
      success: function( msg ) {
        console.log('msg is ' + msg);
        length = msg.length;
        console.log('length is ' + length);
        if (length > 13) { // no idea why a blank msg has a length of 13!!
          alert(msg);
          $("#main").load('?app=$app&func=$func&sub=ajax&ajaxSub=edit_project&cat=' + cat + '&proj_id=' + $proj_id).fadeIn('fast');
        }
        else {
          $("#main").load('?app=$app&func=$func&sub=ajax&ajaxSub=project_detail&cat=' + cat + '&proj_id=' + $proj_id).fadeIn('fast');
        }
      }
    });
    return false;
}); 
  • 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-05T19:47:43+00:00Added an answer on June 5, 2026 at 7:47 pm

    Instead of

    length = msg.length;
    

    try with

    length = msg.replace(/\s/g,'').length
    

    Note

    But you should make sure that there are no spaces or newlines within <?php and ?> tags, I would be better if you remove them.

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

Sidebar

Related Questions

I'm posting data using jquery/ajax and PHP at the backend. Problem being, when I
I'm using jQuery's AJAX function to send a message from a contact form -
How to send a javascript array to PHP using Jquery Ajax.(Note: i will get
I'm using jQuery.ajax to extract form data from a page, and send it to
I am using ajax jquery to send data to php, as data I am
I tried to just send some information to a php file using Jquery Ajax.
I'm used to send passing data with the jQuery form pluging using data: $(form#myform).serialize()
I am using jquery ajax to send data from a <textarea name=comments> . to
I am sending a html form using jquery to ajax, When I send the
i want to send a javascript array to php using jquery ajax. $.post(controllers/ajaxcalls/users.php, {

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.