Reputation: 858
I am trying to pass variables from javascript to a php where it can execute somethings , but the php file is not being called or not being executed , and ive checked , the php file works properly on its own.
$(function () {
$('#comments').click(function () {
var data1 = '4';
var data2 = yes;
var data3 = '26';
$.post('new.php', 'val=' + data1, function (response) {
alert(response);
});
return false;
});
});
<div id='comments'>
<a href="#" onclick="doSomething();" >Click Me!</a></div>
Could someone please point out the mistake ive done :)
Cheers
Upvotes: 0
Views: 99
Reputation: 6000
From the snippet you've posted the main problem is that you're referencing an undeclared variable, yes
.
Maybe you intended to write true
. JavaScript boolean values are just true
, and false
.
Also doSomething
appears to be undeclared, but in this case since you're already handling this in the JS code $('#comments').click()
,
you should remove the onClick
listener from the element.
Upvotes: 2
Reputation: 22619
Change your ajax post data settings. Try below code
$.post('new.php', {val:data1}, function (response) {
});
See examples at jQuery POST
Upvotes: 1