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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:35:55+00:00 2026-05-16T07:35:55+00:00

Currently my AJAX is working like this: index.php <a href=’one.php’ class=’ajax’>One</a> <div id=workspace>workspace</div> one.php

  • 0

Currently my AJAX is working like this:

index.php

<a href='one.php' class='ajax'>One</a>    
<div id="workspace">workspace</div>

one.php

$arr = array ( "workspace" => "One" );
echo json_encode( $arr );

ajax.js

jQuery(document).ready(function(){
    jQuery('.ajax').live('click', function(event) {
        event.preventDefault();
        jQuery.getJSON(this.href, function(snippets) {
            for(var id in snippets) {
                jQuery('#' + id).html(snippets[id]);
            }
        });
    });
});

Above code is working perfectly. When I click link ‘One’ then one.php is executed and String “One” is loaded into workspace DIV.

Question:

Now I want to submit a form with AJAX. For example I have a form in index.php like this.

<form id='myForm' action='one.php' method='post'>
 <input type='text' name='myText'>
 <input type='submit' name='myButton' value='Submit'>
</form>

When I submit the form then one.php should print the textbox value in workspace DIV.

$arr = array ( "workspace" => $_POST['myText'] );
echo json_encode( $arr );

How to code js to submit the form with AJAX/JSON.

Thanks

  • 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-16T07:35:55+00:00Added an answer on May 16, 2026 at 7:35 am

    Submitting the form is easy:

    $j('#myForm').submit();
    

    However that will post back the entire page.

    A post via an Ajax call is easy too:

    $j.ajax({
        type: 'POST',
        url: 'one.php',
        data: { 
            myText: $j('#myText').val(), 
            myButton: $j('#myButton').val()
        },
        success: function(response, textStatus, XMLHttpRequest) {  
            $j('div.ajax').html(response);
        }
    });
    

    If you then want to do something with the result you have two options – you can either explicitly set the success function (which I’ve done above) or you can use the load helper method:

    $j('div.ajax').load('one.php', data);
    

    Unfortunately there’s one messy bit that you’re stuck with: populating that data object with the form variables to post.

    However it should be a fairly simple loop.

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

Sidebar

Related Questions

I am currently working on a fun project, which involves Ajax, HTML, JavaScript, PHP
How is it that tools like this one can make an ajax style call
I'm currently working on a small application that works like this: When the user
I'm currently working on an AJAX file upload script, which works like a charm
I am working with an Ajax imageuploader from this SITE . I currently achieve
I am currently working on some Ajax heavy code and I am wondering how
I am currently working on a ASP.NET AJAX application. Having decided to not use
I am working on a AJAX/jquery notification script. Currently it retunrs a whole fhtml
I am currently executing AJAX query stores on each onblur if this.value is not
I currently have a PHP form that uses AJAX to connect to MySQL and

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.