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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:50:09+00:00 2026-05-30T16:50:09+00:00

I am wanting to use the AJAX function via jQuery to return some data

  • 0

I am wanting to use the AJAX function via jQuery to return some data onto my homepage. Currently, I am using an ‘action=’ on my form to an external PHP file just to check that the data is being sent and it is. I’m now wanting to use AJAX to return this data into a div on my homepage. I have this code but at the moment it’s not returning any data:

$("#ticketSearch").click(function(e) {
  e.preventDefault();
    var eNameData = ("#postcodeSearch").val();
      alert('#ticketSearch clicked'); //this alert doesn't even work!

    var dataToSend = 'postcodeSearch=' + eNameData;

    $.ajax({                
        url: "index.php", 
        type: "POST",
        data: dataToSend,     
        cache: false,
        success: function(php_output)
            {
            $("#ticketResults").html(php_output).show();
            }
    }); 
});

The code for the form:

<form name="pcSearchForm" id="pcSearchForm" class="pcSearchForm"  method="post" action="postCodeSearch.php"> // the action method needs to be taken out

        <input type="text" name="postcodeSearch" id="postcodeSearch" class="postcodeSearch" placeholder="Postcode..." /> 

        <input type="submit" name="ticketSearch" id="ticketSearch" class="ticketSearch" value="Search" /> 

</form>

Any help is much appreciated, I think I am on the right lines but something just isn’t right!
Thank you.

EDIT: New code:

$(document).ready(function() {
  $("#ticketSearch").click(function(e) {
alert("click");
e.preventDefault();
var eNameData = $("#postcodeSearch").val();
 alert('eNameData');
 });

var dataToSend = 'postcodeSearch=' + eNameData;

    $.ajax({                
        url: "index.php", 
        type: "POST",
        data: dataToSend,     
        cache: false,
        success: function(php_output)
            {
            $("#ticketResults").html(php_output);
            alert("#ticketResults");
            }
    }); 
}); 

The form:

        <input type="text" name="postcodeSearch" id="postcodeSearch" class="postcodeSearch" placeholder="Postcode..." /> 

        <input type="button" name="ticketSearch" id="ticketSearch" class="ticketSearch" value="Search" />


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

    You are doing it wrong dude 🙂 ..

    Change

    var eNameData = ("#postcodeSearch").val();
    

    to

    var eNameData = $("#postcodeSearch").val();
    

    I wonder why you use alert('#ticketSearch clicked'); .

    What’s its use. If you need to alert the data postcodeSearch,

    then just do

     alert(eNameData'); 
    

    Hope this helps you 🙂

    EDIT:

    Your code seems to be wrong, Your click event is closed before the ajax call is done. Also i think you are calling the wrong file. Your form submit action page is postCodeSearch.php but in ajax you are calling index.php

    Your code should be changed to :

    FORM :

    <form name="pcSearchForm" id="pcSearchForm" class="pcSearchForm"  method="post" action="postCodeSearch.php"> // the action method needs to be taken out
    
            <input type="text" name="postcodeSearch" id="postcodeSearch" class="postcodeSearch" placeholder="Postcode..." /> 
    
            <input type="button" name="ticketSearch" id="ticketSearch" class="ticketSearch" value="Search" /> 
    
    </form>
    

    JS:

    $(document).ready(function() {
        $("#ticketSearch").click(function(e) {
           var eNameData = $("#postcodeSearch").val();
           var dataToSend = 'postcodeSearch=' + eNameData;
    
           $.ajax({                
               url: "postCodeSearch.php", 
               type: "POST",
               data: dataToSend,     
               cache: false,
               success: function(php_output) {
                   $("#ticketResults").html(php_output);
               }
           }); 
        }); 
    }); 
    

    Hope this helps you. 🙂

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

Sidebar

Related Questions

I have a javascript function which asks for some ajax data and gets back
On my website I use a long polling jquery ajax function. This ajax call
I am wanting to use the Facebox plugin for JQuery but am having a
I'm wanting to use jQuery to wrap a mailto: anchor around an email address,
I am wanting to use jquery to do a show/hide of a DIV from
I'm wanting to use the jquery dialog to open a modal dialog, and in
I have a jQuery .ajax call: $j.ajax({ type: POST, url: /Services/Cart.asmx/UpdateQuantity, data: data, contentType:
I am currently working on some prototypes for a web site I am wanting
Wanting to use: Ajax Event Calendar but the dates are in american format, how
When I use Ajax call(jquery) in the HEAD section I find a waiting for

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.