-1

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

7
  • What is the output of the "<?php bloginfo('url') ?>./getData.php",? Commented Sep 5, 2013 at 11:16
  • Maybe you have also an extra dot . in your url variable? Commented Sep 5, 2013 at 11:16
  • Hello Priya does alert(val); this is alerting..? Commented Sep 5, 2013 at 11:17
  • What is the exact path of you getData.php ? And what is the output of bloginfo('url')? Commented Sep 5, 2013 at 11:20
  • getData.php is in my localhost/wordpress/themes/eleganetnews/ folder Commented Sep 5, 2013 at 11:39

4 Answers 4

1

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') ?

Sign up to request clarification or add additional context in comments.

1 Comment

can you mention the path to 'getData.php' or check that with the bloginfo('url')/getData.php, try echo it in php, echo bloginfo('url') ?>.'/getData.php';
0

try this:

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

you forgot to echo the bloginfo('url')

1 Comment

I tried debugging the jquery code..the control is not going inside $.ajax({ )} function. Do i need to register any file for this ?
0

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",

1 Comment

Sorry..nothing is working..can you please help me..i need to pass some i/p parameter to getData.php and return some text value to the jquery file as a result
0

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

5 Comments

Then can you pls tell me an alternate good practivce to resolve this issue
Keep the value in hidden field and then you can access it in your javascript.
Do you have firebug add on install in your firefox browser, If so please check the ajax request url in the firbug that it is being called without any error.
yes i debugged jquery with chrome, but the control itself is not going to ajax functions.It is going to other local functions and jquery files, but not at all going to the ajax functions.Since the control is not going to the $.ajax{()} call, i am not able to debug. Can anybody pls help me.I am using this in wordpress.do i need to do anything in wordpress to make the jquery ajax workable in wordpress ?
on your page in html add the input field <input type="hidden" name="blog-info-url" id="blog-info-url" value="<?php echo bloginfo('url')?>"> then in your javascript code url: $('#blog-info-url').val()+"/getData.php"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.