1

I am creating a plugin in wordpress. I am trying to get the img url and file url in jQuery. Code below. What did I do wrong?

$('.result_tag')
  .append('<img src="plugin_dir_url( __FILE__ ).'remove_sign.png'" >');

$.post("plugin_dir_url( __FILE__ ).'delete.inc.php'", {
    tag : text,/
  },
  function(data){
      $("#result_tag").html(data); 
});

1
  • The quoting looks broken in your first line - haven't you got nested single-quotes? Commented Mar 4, 2015 at 22:10

1 Answer 1

2

supposing you are working in a .php file, you are missing the php tags <?php ?>

$('.result_tag')
  .append('<img src="<?php echo plugin_dir_url( __FILE__ ).'remove_sign.png' ?>" >');

$.post("<?php echo plugin_dir_url( __FILE__ ).'delete.inc.php' ?>", {
    tag : text,/
  },
  function(data){
      $("#result_tag").html(data); 
});

just change

'<img src="plugin_dir_url( __FILE__ ).'remove_sign.png'" >'

to

'<img src="<?php echo plugin_dir_url( __FILE__ ).'remove_sign.png' ?>" >'
Sign up to request clarification or add additional context in comments.

3 Comments

I had tried those way, add <?php echo ;?>, but still no luck.
jquery, so far, I figure out a way to do it by hidden input, and call it by jquery. It is OK. But how come in jquery, it cannot call the url, I guess php load in server side, jquery load in client side, so put dir_url in jquery, it will call the client side user url, am I right?
is this code in a .js file or in a '.php' file? are you getting any javascript error? are you using Firebug or something like that where you can debug the ajax call or js erros?

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.