Skip to content Skip to sidebar Skip to footer

Sending Span Text To Another Page With Js And Php

I have a dynamically changing span on a page displaying the number of votes a project has received. On another (target) page i have a list of projects. i want to be able to display

Solution 1:

Try this, use .text() instead of .text

var prj1c = $("#count1").text(); //instead of  var prj1c = $("#count1").text;
$.ajax({
    type: "POST",
    url: "yourpage.php",
    data: {count :prj1c},
    success: function(response) {
         alert("Response "+response);
    }

 });

in yourpage.php add this <?php echo $_POST['count']; ?>

Update:

 $(function(){

     $("#count1").click(function(){
           window.location='page2.php?count='+$(this).text();
      });

});

in page2.php:

<ul><liid="projectName"><img><span>vote count goes HERE: <?phpecho$_GET['count']; ?></span></li></ul>

Solution 2:

You can try with jQuery Ajax request. When user vote up/down you can make an ajax call to the target page.

Eg.

var prj1c = $("#count1").text();

$.ajax({
        type: "POST",
        url: "targetPage.php",
        data: "count="+prj1c,
        success: function(response) {
             alert("Response "+response);
          }

 });

Get the prj1c value in targetPage.php

$prj1c = $_REQUEST['count'];
 // Follow appropriate steps later in targetPage.php

Post a Comment for "Sending Span Text To Another Page With Js And Php"