Reputation: 575
I have many links like this... different link id me for different items
<a class="member" href="http//ex.com/action.php?me=1">link1</a>
so when I click this I want to navigate to action.php
from here (here.php
)
I am using ajax to do this.
I'm new to jQuery.. I am not able to understand the usage the url
parameter.. I tried many posts found here... wanted to the basic way to send the --me-- value from here.php
to action.php
..
$("a.member").click(function(e) {
$.ajax({
type: "GET",
url: "action.php?",
data: "me=" + me,
success: function (data) {
alert(data);
}
});
return false;
e.preventDefault();
});
Upvotes: 3
Views: 57836
Reputation: 1693
Here is an example,
The jquery part:
$("#update").click(function(e) {
e.preventDefault();
var name = 'roger';
var last_name = 'blake';
var dataString = 'name='+name+'&last_name='+last_name;
$.ajax({
type:'POST',
data:dataString,
url:'insert.php',
success:function(data) {
alert(data);
}
});
});
The insert.php page
<?php
$name = $_POST['name'];
$last_name = $_POST['last_name'];
$insert = "insert into TABLE_NAME values('$name','$last_name')";// Do Your Insert Query
if(mysql_query($insert)) {
echo "Success";
} else {
echo "Cannot Insert";
}
?>
Note: do not use mysql_* functions
Hope this helps,
Upvotes: 10
Reputation: 8487
Try this :
$.ajax({
type: "GET",
url: "action.php",
data: {
me: me
},
success: function (data) {
alert(data);
}
});
Upvotes: 7
Reputation: 97672
Since the parameter is already in the <a>
's href url just pass that to url
$("a.member").click(function(e){
$.ajax({
type: "GET",
url: this.href,
success: function(data){
alert(data);
}
});
return false;
});
Upvotes: 2