Title: WP Ajax HTTP code 400
Last modified: September 11, 2018

---

# WP Ajax HTTP code 400

 *  Resolved [freewill7](https://wordpress.org/support/users/freewill7/)
 * (@freewill7)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wp-ajax-http-code-400/)
 * Hi everyone, it’s my first post here.
    I’m getting into the wordPress’s world
   by writing a plugin. However, my plugin should use ajax but it doesn’t really
   work. So, here’s my main file’s content:
 *     ```
       add_action("wp_ajax_nopriv_lbuilder_select", "lbuilder_ajax");
   
       function lbuilder_ajax(){
       	$type = $_GET['type'];
       	echo $type;
       	die();
       }
       ```
   
 * It’s pretty easy. Now the jQuery code:
 *     ```
       		var data = {
       			'action': 'lbuilder_select',
       			'type': 'snk'
       		};
       		console.log(lbuilder.ajaxurl);
       		$.get(lbuilder.ajaxurl, data, function(response){
       			$('#lbuilder *').remove();
       			$('#lbuilder').append(response);
       		});
       ```
   
 * lbuilder.ajaxurl was passed by the wp_localize_script:
 *     ```
       	public function load_stuff(){
       			wp_register_script('lbuilder-script', plugin_dir_url( __FILE__).'assets/js/main.js', array('jquery'), NULL, false);
       			wp_register_style('lbuilder-style', plugin_dir_url(__FILE__).'assets/css/lbuilder-form.css');
       			$lbuilder = array(
       				'ajaxurl' => admin_url('admin-ajax.php')
       			);
       			wp_localize_script('lbuilder-script', 'lbuilder', $lbuilder);
       	}
       add_action('init', 'load_stuff');
       ```
   
 * Now, what am I doing wrong? I hope you can help me.
    bye
 * EDIT: I solved it: I was trying the script as registered user so I had to add`
   add_action('wp_ajax_lbuilder_select');`
    -  This topic was modified 7 years, 9 months ago by [freewill7](https://wordpress.org/support/users/freewill7/).
    -  This topic was modified 7 years, 9 months ago by [freewill7](https://wordpress.org/support/users/freewill7/).
    -  This topic was modified 7 years, 9 months ago by [bcworkz](https://wordpress.org/support/users/bcworkz/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wp-ajax-http-code-400/#post-10678005)
 * I’m glad you figured that out! This reply serves to take your topic off the “
   No Replies” list we use to find those still needing help. You may disregard.
 *  [Kimsea Sok](https://wordpress.org/support/users/basicblogtalk/)
 * (@basicblogtalk)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/wp-ajax-http-code-400/#post-10679570)
 * Is that working now?
 * If it does, you use wp_send_json for response data. for information check the
   document
 * [https://developer.wordpress.org/reference/functions/wp_send_json/](https://developer.wordpress.org/reference/functions/wp_send_json/)
 * Make sure all input data is validated and sanitize

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WP Ajax HTTP code 400’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 3 participants
 * Last reply from: [Kimsea Sok](https://wordpress.org/support/users/basicblogtalk/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/wp-ajax-http-code-400/#post-10679570)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
