0

This is the next step forward to this question

I have the script below

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function doSomething() {
    $.get("somepage.php");
    return false;
}
</script>

<a href="#" onclick="doSomething();">Click Me!</a>

My question is, if I want to send a value to somepage.php page once someone click on the link, how do I do it.

My new a link look like this <a href="#" onclick="doSomething(<?php echo $id; ?>);">Click Me!</a>

Community
  • 1
  • 1
nasty
  • 6,797
  • 9
  • 37
  • 52
  • 2
    this link might help u... http://stackoverflow.com/questions/6130662/passing-javascript-variable-to-php-using-ajax – Maddy Oct 01 '12 at 05:55

2 Answers2

1

Try this...

function doSomething(id) {
    $.get("somepage.php?id="+id);
    return false;
}

OR

function doSomething(id) {
    $.get("somepage.php", { id: id } );
    return false;
}
Ashwini Agarwal
  • 4,828
  • 2
  • 42
  • 59
0
function doSomething(myData ) {    
$.get("somepage.php" , {'data': myData } , function(result){
    });
}

Here the data is sent using a key value pair.. If you want to something with the returned data handle it in the callback function. Otherwise you can remove it ..

Sushanth --
  • 55,259
  • 9
  • 66
  • 105