Title: wp_localize_script was called incorrectly
Last modified: August 24, 2016

---

# wp_localize_script was called incorrectly

 *  [giwrgos88](https://wordpress.org/support/users/giwrgos88/)
 * (@giwrgos88)
 * [11 years ago](https://wordpress.org/support/topic/wp_localize_script-was-called-incorrectly/)
 * Hi,
    when I’m enabling the debugging for the website I’m getting the following
   message
 *     ```
       PHP Notice:  wp_localize_script was called <strong>incorrectly</strong>. Scripts and styles should not be registered or enqueued until the <code>wp_enqueue_scripts</code>, <code>admin_enqueue_scripts</code>, or <code>login_enqueue_scripts</code> hooks. Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.3.) in /www/*****/wp-includes/functions.php on line 3049
       ```
   
 * The reason is because one function that I did for my plugin, where I’m using 
   the admin-ajax.php for ajax request
 * Here is the sort of the data that I have inside my index file of the plugin
 * Action which I’m using it to collect data from database using AJAX GET
 *     ```
       add_action("wp_ajax_collect_admin_row_data", "collect_admin_row_data");
       include (ABSPATH ."wp-content/plugins/my_plugin/include/actions/admin_collect_row_data.php");
       ```
   
 * Next I have the following function
 *     ```
       $jquery_pages =array("user_area");
   
       if ($GLOBALS['pagenow'] == "admin.php")
       {
           $page = $_GET["page"];
   
           if (in_array($page, $jquery_pages))
           {
               add_action('admin_enqueue_scripts', "ajaxpaging_location");
           }
           else if ($page == "il_menu")
           {
               add_action('admin_enqueue_scripts', "menu_options");
           }
       }
   
       function ajaxpaging_location() {
   
           if (DEV_MODE)
           {
               wp_enqueue_script('ajaxscript', AJAXACTIONS.'js/jquery.actions.js', array('admin_custom_jquery_script'));
   
           }
           else
           {
               wp_enqueue_script('ajaxscript', AJAXACTIONS.'js/jquery.actions.min.js', array('admin_custom_jquery_script'));
           }
           wp_localize_script( 'ajaxscript', 'ajaxpagingscript', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
   
       }
       ```
   
 * Inside jquery.actions.js I have the following code
 *     ```
       function callGetAjaxRequest(parameters, sync_value)
       {
           var result="";
   
           jQuery.ajax({
               cache: true,
               type: 'GET',
               accepts : 'json',
               async: sync_value,
               url: ajaxpagingscript.ajaxurl,
               data : parameters,
               success: function(data) {
                   result = data.message;
               },
               error : function (data)
               {
                   result = data.responseJSON;
                   errorMessageController(data.responseJSON.message);
               }
           });
           return result;
       }
       ```
   
 * The code is working fine but it throws the notice.
    What actually I’m doing wrong
   and I get this notice?

The topic ‘wp_localize_script was called incorrectly’ is closed to new replies.

## Tags

 * [admin-ajax.php](https://wordpress.org/support/topic-tag/admin-ajax-php/)
 * [ajax](https://wordpress.org/support/topic-tag/ajax/)
 * [wp_localize_script](https://wordpress.org/support/topic-tag/wp_localize_script/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [giwrgos88](https://wordpress.org/support/users/giwrgos88/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/wp_localize_script-was-called-incorrectly/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
