I want to get the value of an href using java script and then pass it to another file of php, I did the code of JS and some friend add J query to it, in order to pass the value to the test.php file, but I don't why it is not working.
<script>
$(function(){
$('div#tabs ul li a').click(function() {
var n = $(this).attr('href');
var p=n.slice(5,6);
alert(p);
$.ajax({
type: 'post',
url: 'test.php'
data: {value : p}
success: function(data) {
//do something with response 'data'
}
});
});
</script>
You're missing a final });
(and a few commas) in your code example. It should look like this:
<script>
$(function(){
$('div#tabs ul li a').click(function() {
var n = $(this).attr('href');
var p = n.slice(5, 6);
alert(p);
$.ajax({
type: 'post',
url: 'test.php',
data: {value : p},
success: function(data) {
// Do something with response 'data'
}
});
});
});
</script>
When creating a set in javascript, the key/value pairs need commas:
<script>
$(function(){
$('div#tabs ul li a').click(function() {
var n = $(this).attr('href');
var p=n.slice(5,6);
alert(p);
$.ajax({
type: 'post',
url: 'test.php',
data: {value : p},
success: function(data) {
//do something with response 'data'
}
});
});
});
</script>