0

when i using wordpress ajax

in function.php

add_action( 'wp_enqueue_scripts', 'indexnews_scripts' );
function indexnews_scripts() {
                              if(is_home()){
    wp_enqueue_script( 'script-name', get_template_directory_uri() .'abc.js', array('jquery'), '1.0.0', true );
    wp_localize_script( 'script-name', 'MyAjax',array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
                             }}

in the front end it always shows

<script type='text/javascript'>
      /* <![CDATA[ */
      var MyAjax = {"ajaxurl":"http:\/\/127......\/wp-admin\/admin-ajax.php"};
 /* ]]> */
</script>

is there any way keep this code hide in the front end?

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83

1 Answers1

0

If by 'front end', you mean that the user can expose the scripts by viewing the page's source code and looking for JavaScript?

I'm afraid it's not possible to hide JavaScript. If you need to use it, it must be exposed. See this question

If however you mean it 'shows' as in it actually writes that text to the page when the user is viewing the page normally, that may be a missing HTML tag, or something similar...

Community
  • 1
  • 1
1owk3y
  • 1,115
  • 1
  • 15
  • 30
  • is there any way not showing the "http:\/\/127......\/wp-admin\/admin-ajax.php" stuff hen using wordpress ajax, – taylortribbiani Mar 16 '15 at 07:50
  • i do know the js i wrote will be review anyway but why the url of admin-ajax.php will be post – taylortribbiani Mar 16 '15 at 07:53
  • Sadly, no. Even if you could encode the URL to make it unreadable, you would also need to add a function to decode the URL so that the browser could make an AJAX request on it. A malicious user could easily exploit that function to decode the URL, rendering the attempt to hide the URL pointless. If you just wanted to very weakly hide it from users just poking around, you could try encoding/decoding the URL: http://stackoverflow.com/questions/22555643/is-there-any-js-library-to-obscure-string-manipulation – 1owk3y Mar 16 '15 at 07:56
  • is there any way using ajax without using "wp_localize_script" thank you – taylortribbiani Mar 16 '15 at 08:33