简体   繁体   中英

How do I get a php value in Jquery?

Hey guys I have this populated search form that will bring a table of people based on search result. I need to be able to get the php variable that has the username I am trying to get, then that will get sent over to .php file using the JQuery UI which will open a notes window.

So here:

username, other, other , notes - this is a link and once clicked the following is called:

$(document).ready(function () {
    $("#NotesAccessor").click(function () {

      alert(notes_name);
      run();
    });
    });

which leads to :

function run(){ var url = '/pcg/popups/grabnotes.php'; showUrlInDialog(url); }

to a function that opens the Jquery Dialog.

I need to access the username of the based notes that was clicked....if there was 20 results of different names, david, joe, john, etc... I click the notes with david as username, I need that to be sent over to the file that is opening so I can display the based notes on the appropriate username.

Here is my php:

.........
    <td>
        $csvusername
    </td>
.........
    <td>
    ";
      if ($checkNotes[1] == 'No')
    {
        echo "None";
    }
    if ($checkNotes[1] == 'Yes')
    {
            echo "<a href='#' id='NotesAccessor'>Click to access</a>";
    }
    echo "
    </td>
........

Let me know if this makes sense to you. I am kinda stuck on this and could use a hand :)

David

I can't tell what PHP variable you are trying to get, but generally, you can do:

<!-- /myScript.php?myVar=helloWorld -->
<script type="text/javascript">
    $(document).ready(function(){
        var myPhpVar = <?php echo $_GET['myVar']; ?>;
        alert(myPhpVar);
    });
</script>
<script>
var x = '<?php echo $variable; ?>';
or
var x = '<?php echo my_function(); ?>'; 
</script>


<?php
function my_function()
{
  return $variable;
}
?>

this should do what you like :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM