Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

jquery and php ajax

Guest
Aug 02, 2011 Aug 02, 2011

Hi

I have a Front.php page which loads an external php page using:

<script type="text/javascript">
        $(document).ready(function() {

          //burnbackend is echoed to div commentfeed.
        $("#commentfeed").load("burnbackend.php");
               
            
            $("#shuffle").submit(function(){
                var voteone= $("#voteone").val();
                $.get("burnbackend.php", { voteone : voteone},  function(data) {
                    $("#commentfeed").html(data);
                    });      
                      
        });
</script>

//inside body

<div id="commentfeed"></div>


burnbackend.php is a page that echos a form the problem is that using jquery ajax I would like to submit the echoed form

to burnbackend.php  and load a different result.

burnbackend.php

<?Php

if($_GET['voteone'])

{

//Here the submit of the vote is done and some database stuff.

echo "vote done";

echo'

<form name="shuffle" id="shuffle" action="" method="get">
<input type="hidden" id="voteone" value="VOTE HERE"/><br/>
<input type="submit" id="submit" value="SHUFFLE BUTTON"/><br/>
</form>';

}

else

{

echo'

<form name="shuffle" id="shuffle" action="" method="get">
<input type="hidden" id="voteone" value="VOTE HERE"/><br/>
<input type="submit" id="submit" value="SHUFFLE BUTTON"/><br/>
</form>';

}

?>

The problem in a way goes like this: How do I submit an echoed form from a loaded external page using j query from the

page that loads the external page.

Thanks.

Please ask more questions if the problem is un understandable.

TOPICS
Server side applications
655
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 02, 2011 Aug 02, 2011

Hi

You include the link to the form processing script in the action element of the form -

<form name="shuffle" id="shuffle" action="" method="get">

I would also advise using post and not get as the method.

PZ

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 03, 2011 Aug 03, 2011
LATEST

Hi thanks for reply

I changed assignments to post. I also linked the form to the Front.php that has the Jquery. Its posts

and a get a sucess but the current Front.php instantly changes to the backend.php which is

the page loaded into Front.php and contains the posting form: I need to do the post and keep Front.php but

just change the backend.php thats is load on Front.php

Code:

Front.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery/jquery-1.4.2.min.js"></script>

<script type="text/javascript">
        $(document).ready(function() {
   
           
              $("#shuffle").submit(function() {
              var voteone= $("#voteone").val();
              $.post("burnbackend.php", { voteone : voteone},  function(data) {
                    $("#commentfeed").html(data);
              });
       
            });
           
           
           
        });
</script>
</head>

<body>

<div id="commentfeed"></div>
</body>
</html>

Backend.php


<?Php


$morecapture=$_GET['expid'];

$motion=$_POST['voteone'];

if($motion)
{
echo 'vote done';

echo'<form name="shuffle" id="shuffle" action="burnout.php" method="post">
<input type="hidden" id="voteone" value="VOTE HERE"/><br/>
<input type="submit" id="submit" value="SHUFFLE BUTTON"/><br/>
</form>';

}

?>

So as you can see. Front.php loads backend.php through Jquery. backend.php has an echoed form that I am trying to submit using

jquery from Front.php and changing what was original loaded from backend.php

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines