Solved

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

Posted on 2011-03-15
4
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

732 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