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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:11:03+00:00 2026-06-17T09:11:03+00:00

Hi I am just learning to work with jQuery/ajax.And I seem to be having

  • 0

Hi I am just learning to work with jQuery/ajax.And I seem to be having some problems.When I trying to post some form data , I get back from the server my entire html structure and the data I am returning.

This is my html:

   ....
   <form id="submitData" method="post" action="">
        <div>
            <label for="FirstName">First Name:</label>
            <input type="text" id="FirstName" name="FirstName"/><span class="error">*</span>
        </div>
        ........
        <div id="textearea">
            <label for="Message">Message:</label>
            <textarea name="Message"></textarea><span class="error">*</span>
        </div>
        <input type="submit" id="submit" name="submit" value="Submit"/>
    </form>
    .....

This is my php code :

<?php
      if(isset($_POST['data'])){
          $jsonData = json_encode($_POST['data']);

          return $jsonData;
      }
   ?>

And this is my jQuery code:

$(document).on('submit' , 'form#submitData' , function(e){

     var formData = $(this).serializeArray();
     console.log(formData);

     $.ajax({
         url:'index.php',
         type:'POST',
         datatype:'json',
         data: { data : formData},
         success : function(data){
             for(var i = 0; i < data.length; i++){
                 console.log(data);

             }
         },
         error : function(s , i , error){
             console.log(error);
         }
     })
     e.preventDefault();
 });

I have tryed accesing the data in a loop but I seem to be getting back the letter from the html structure.I should also mention that that the html for the form is loaded into the page using jquery load().

How can I make it so that I ge back only the encoded data ?

  • 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-17T09:11:03+00:00Added an answer on June 17, 2026 at 9:11 am

    get it from a separate PHP page :

    $(document).on('submit' , 'form#submitData' , function(e){
    
         var formData = $(this).serializeArray();
         console.log(formData);
    
         $.ajax({
             // change here
             url:'ajax.php',
             type:'POST',
             datatype:'json',
             data: { data : formData},
             success : function(data){
                 for(var i = 0; i < data.length; i++){
                     console.log(data);
    
                 }
             },
             error : function(s , i , error){
                 console.log(error);
             }
         })
         e.preventDefault();
     });
    

    and put your PHP code there.

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

Sidebar

Related Questions

I'm just learning how to use iterators over vectors, and I'm having some trouble
I'm just learning how to utilise ajax/json with jquery and I've hit a brick
Gidday Just learning the jquery UI, and have made some really good progress today,
Hi there Stack Overflow, I'm new at learning jQuery and just trying to condense
I have just currently started learning jQuery and I seem to be able to
I am learning jquery and can't seem to find what I need to get
Just learning the world of jquery, and all my googling gives examples like this:
Im just learning mod_rewrite and regex stuff, and what I'm trying to do is
Im just learning SQLite and I can't get my parameters to compile into the
I am trying to add ajax into my form so I can submit the

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.