user2439019
user2439019

Reputation: 9

JQuery ajax is not calling the php page

I have a list of check boxes and on click event of a button i am passing the vlaue of the clicked chk box to a php file, and in that php file i am retrieving some text data from mysql db and returns to the jquery fileand displays that text data in a text area. But the control is not going to the php file, but its coming to the jquery file. I am very new to wordpress. so i dnt kow what to do and anything need to be done.

Pls find my code below.

jQuery( document ).ready( function( $ ) {

$("#save_value").on('click',function(){

var val = [];

$("input:checked").each(function(i){

val[i] = $(this).val();

});

alert(val);
$.ajax({

type:'POST',
url: "<?php bloginfo('url') ?>./getData.php",

success: function(data) {
// $('#result').html(data);
alert(data);

}
});
});
});

and my php file is

<?php
echo 'hi';
$output = "returned data from ";
echo $output;
?>

my php file is in theme folde and jquery file is in js folder under theme folder.

Can anybody pls help me to find out a solution.

Thanks Priya

Upvotes: -1

Views: 86

Answers (4)

rohitcopyright
rohitcopyright

Reputation: 342

I would suggest not to use php code in javascript codes. This is not a good programming practice.

Upvotes: 0

lshettyl
lshettyl

Reputation: 8181

Why not just:

url: "/getData.php", //if this file is at root

Otherwise:

url: "<?= bloginfo('url') ?>/getData.php", //provided short_open_tag is turned on

or

url: "<?php echo bloginfo('url') ?>/getData.php",

Upvotes: 0

Sobin Augustine
Sobin Augustine

Reputation: 3765

try this

 url: "<?php echo bloginfo('url') ?>/getData.php"

you should echo the bloginfo('url') and no need of that '.' to join them.

did you check bloginfo('url') ?

Upvotes: 1

roullie
roullie

Reputation: 2820

try this:

url: "<?php echo bloginfo('url') ?>./getData.php",

you forgot to echo the bloginfo('url')

Upvotes: 0

Related Questions