In jquery ajax function, how can php variable pass through url?
php : send.php?id=<?php '.$news_id.' ?>
$.ajax({
type: "POST",
url: "ABOVE URL",
data: str});
In jquery ajax function, how can php variable pass through url?
php : send.php?id=<?php '.$news_id.' ?>
$.ajax({
type: "POST",
url: "ABOVE URL",
data: str});
<head>
<script type="text/javascript">
...
$.ajax({
type: 'POST',
url: 'send.php?id=<?php echo $news_id; ?>',
data: str
});
...
Like that?
Are you wanting to pass the value of the href to the URL of the ajax call? Assuming you're clicking on a link?
$('a.thisLink').click(function(){
$.ajax({
type: "POST",
url: $(this).attr('href'),
data: str
});
});
If you want to pass a value from a form to send.php, you can do that like this.
function sendFormData(formData){
$.ajax({
type: "POST",
url: 'send.php',
data: formData
})
};
// when the form is submitted
$('form[name=foo]').submit(function(){
// pass the entire form?
var formData = $(this).serialize();
// or just one input?
var formData = $('form[name=foo] input[name=bar]').val();
sendFormData(formData);
});