Solved

with jquery/ajax how do I run a php script in the same file?

Posted on 2011-03-15
4
249 Views
Last Modified: 2012-05-11
I have this code at the moment which posts to a external php file...

<script>
    $(document).ready(function (){
         $('form[name=form1]').submit(function (){
                $.post("/forms/yes-reference-process.php", $('form[name=form1]').serialize(), function(data){$('#msg').html(data);});
                return false;
         });
    });
</script>
<h2>Enter Booking Reference</h2>
<h3>You should have been told or emailed this by our staff . </h3>
<form id="form1" name="form1" method="post" action="">
<table width="300" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td><label for="last_name">Last Name</label></td>
    <td><input name="last_name" type="text" id="last_name" /></td>
  </tr>
  <tr>
    <td><label for="reference">Reference</label></td>
    <td><input name="booking_reference" type="text" id="booking_reference" /></td>
  </tr>
    <tr>
    <td colspan="2">For example : 213423</td>
    </tr>
  <tr>
    <td colspan="2"><input name="submit_reference" type="submit" value="Find My Booking"  id="submit"></td>
    </tr>
</table>
</form>
<div id='msg'></div>

how do i add the php to the top and no have to post to external?
0
Comment
Question by:maccaj51
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 167 total points
ID: 35137484
>and no have to post to external?

you can't... you need to send the field name/value of the form to the page. so you need to use ajax ($.post(, $.get(, $('#msg').load(
0
 
LVL 19

Assisted Solution

by:Bardobrave
Bardobrave earned 167 total points
ID: 35137529
You can call your yes-reference-process.php file from $.post with a querystring builded getting values on <form> fields

$.post("/forms/yes-reference-process.php?" + $("#last_name").val() + "&" + $("#booking_reference"), $('form[name=form1]').serialize(), function(data){$('#msg').html(data);});

The problem here is that on your page load, yes-reference-process.php will be fired with the data contained inside those fields at this moment, when they probably are empty
0
 
LVL 3

Assisted Solution

by:pius_babbun
pius_babbun earned 166 total points
ID: 35137533
0
 

Author Closing Comment

by:maccaj51
ID: 35235828
Thanks for your help!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now