4 replies
Hey all,

I am more familiar with php than anything but this has got me stumped...

I have a tell-a-friend script I have created in php and have separated it out into a form and its processing script.

So the idea is that I want to submit the form without a page refresh. I got the idea to use ajax and or jquery to do so.

I have the front end set of things working probably about 85%-95% of the way and 100% on the processing script.

What I am getting hung up on is how to retrieve the php results using Jquery as I know the requested result is being done. i.e. email is being sent. I just need it to be able to return the proper message to the form.

So I think I have narrowed it down to a few lines but am not sure what I am getting wrong here... Your help is appreciated.

PHP Code:
<script>
$(function() {  
  $(".button").click(function() {
    var yourname = $("input#yourname").val();    
    var youremail = $("input#youremail").val();                          
    var friendn1 = $("input#friendn1").val();    
    var email1 = $("input#email1").val();                          
    var friendn2 = $("input#friendn2").val();    
    var email2 = $("input#email2").val();        
    var friendn3 = $("input#friendn3").val();    
    var email3 = $("input#email3").val();                          
    var friendn4 = $("input#friendn4").val();    
    var email4 = $("input#email4").val();                          
    var friendn5 = $("input#friendn5").val();    
    var email5 = $("input#email5").val();                          
    var dataString = 'yourname='+ yourname + '&youremail=' + youremail + '&friendn1=' + friendn1 + '&email1=' + email1 + '&friendn2='+ friendn2 + '&email2=' + email2 + '&friendn3=' + friendn3 + '&email3='+ email3 + '&friendn4=' + friendn4 + '&email4=' + email4 + '&friendn5='+ friendn5 + '&email5=' + email5;
    //alert (dataString);return false;
$.ajax({  
  type: "POST",  
  url: "process.php",  
  data: dataString,  
  success: function() {  

//everything works up until this point...
  $('#message').append("<?=$disc?>")
  }  
});  
return false;
  });  
 });

</script>
For ease of understanding I am adding the link below to grab my project... Its zipped.
http://www.bitsonline.us/david/ajaxtellafriend.zip
#jquery #question
  • Profile picture of the author chuawenching
    try this instead

    $('#message').append("<?PHP $disc; ?>")
    {{ DiscussionBoard.errors[2133309].message }}
    • Profile picture of the author jaybaker
      Nope didnt work.
      Signature

      Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
      - The AC Assassin

      {{ DiscussionBoard.errors[2133851].message }}
  • Profile picture of the author kidino
    I think the ajax part should be like this...

    $.ajax({
    type: "POST",
    url: "process.php",
    data: dataString,
    success: function(data) {

    //everything works up until this point...
    $('#message').append(data)
    }
    });

    in process.php, you can use echo to create the "data" that is received on the jquery. anything you echo in process.php will be the "data". give it a try...
    Signature

    DIPPEC - PHP Script for Selling Digital Products with Paypal. No more monthly SaaS fees. No more commission fees. Keep it all for yourself (except for Paypal fees).

    Free Pricing Table Builder

    {{ DiscussionBoard.errors[2134561].message }}
  • Profile picture of the author jaybaker
    Thanks! It worked!
    Signature

    Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
    - The AC Assassin

    {{ DiscussionBoard.errors[2135476].message }}

Trending Topics