Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-15
4
Medium Priority
?
262 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 501 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 501 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 498 total points
ID: 35137533
0
 

Author Closing Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

609 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