Title: cmdcmdcmd's Replies | WordPress.org

---

# cmdcmdcmd

  [  ](https://wordpress.org/support/users/cmdcmdcmd/)

 *   [Profile](https://wordpress.org/support/users/cmdcmdcmd/)
 *   [Topics Started](https://wordpress.org/support/users/cmdcmdcmd/topics/)
 *   [Replies Created](https://wordpress.org/support/users/cmdcmdcmd/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/cmdcmdcmd/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/cmdcmdcmd/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/cmdcmdcmd/engagements/)
 *   [Favorites](https://wordpress.org/support/users/cmdcmdcmd/favorites/)

 Search replies:

## Forum Replies Created

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

 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Admin-ajax.php 400 error](https://wordpress.org/support/topic/admin-ajax-php-400-error/)
 *  Thread Starter [cmdcmdcmd](https://wordpress.org/support/users/cmdcmdcmd/)
 * (@cmdcmdcmd)
 * [8 years ago](https://wordpress.org/support/topic/admin-ajax-php-400-error/#post-10081744)
 * Ok got it to work 🙂 Thank you very much for your help!!!
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Admin-ajax.php 400 error](https://wordpress.org/support/topic/admin-ajax-php-400-error/)
 *  Thread Starter [cmdcmdcmd](https://wordpress.org/support/users/cmdcmdcmd/)
 * (@cmdcmdcmd)
 * [8 years ago](https://wordpress.org/support/topic/admin-ajax-php-400-error/#post-10079719)
 * Hi guys, I’ve made a new file to implement your process, although mine was working
   previously, still getting a 400 bad request error
 *     ```
       function add_js_scripts() {
       	wp_enqueue_script( 'script',  get_template_directory_uri() . '/js/ajax-nav.js', array('jquery'), '1.0', true );
   
       	// pass Ajax Url to script.js
       	wp_localize_script('script', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
       }
       add_action('wp_enqueue_scripts', 'add_js_scripts');
       add_action('wp_ajax_function_name', 'AjaxVid');
       add_action('wp_ajax_nopriv_function_name', 'AjaxVid');
   
       function AjaxVid(){ 
       	$post_id = $_POST['postid'];
       	$post_title = $_POST['title'];
       	$link = get_field("video_link", $post_id);
       	$_video_type = get_field("video_type", $post_id);
           $client = get_field("client", $post_id);
       	$director = get_field("director", $post_id);
   
   
       	echo '<div id="thevideo">';
           echo '<div class="video_header">';   
       	echo '<div class="item_title">';
       	echo $post_title;
       	echo '</div>';
       	if(!empty($client)):
       	echo '<div class="item_client">';
       	echo $client;
       	echo '</div>';
       	endif;
       	if(!empty($director)):
       	echo '<span class="sep"> | </span>';
       	echo '<div class="item_director">';
       	echo $director;
       	echo '</div>';
       	endif ;				
       	echo '</div>';
       	echo '<div class="video_inner">';
       	if(!empty($link)){
       		if($_video_type == "youtube"){
       		echo '<iframe class="mainvid" width="960" height="540" src="http://www.youtube.com/embed/'. $link .'?enablejsapi=1&iv_load_policy=3&showinfo=0&autoplay=1" frameborder="0" allowfullscreen="1" title="'. $post_title . '"></iframe>';
       						} elseif ($_video_type == "vimeo"){ 
       		echo '<iframe class="mainvid" width="960" height="540" src="http://player.vimeo.com/video/'. $link .'?title=0&wmode=opaque&api=1&autoplay=1" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
       						} elseif ($_video_type == "other"){
       		echo '<iframe src="<?php echo $link ;?>" width="960" height="540" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
       						} 	
       		} 
       		echo '</div></div>';
       	}
       ```
   
 * and js
 *     ```
       (function($) {
   
       	$(document).on( 'touchstart click', '.portfolio_item', function( ) {
       		$port_holder = $('.portfolio_holder');	
       		$video_holder = $('#video_holder');
       		$currentitem = $(this);
   
       		post_id = $(this).attr('data-id');	
       		thetitle = $(this).attr('title');
   
   
       		var str = {
       			'action': 'AjaxVid',
       			'postid': post_id,
       			'title': thetitle,
       		};
       		$.ajax({
       		    type: "POST",
       		    dataType: "html",
       		    url: ajaxurl,
       		    data: str,
       		    success: function(data){
       		        // Code after ajax success
       		    },
       		    error : function(jqXHR, textStatus, errorThrown) {
       		        $loader.html(jqXHR + " :: " + textStatus + " :: " + errorThrown);
       		    }
       		});
       	});
       })(jQuery);
       ```
   
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Admin-ajax.php 400 error](https://wordpress.org/support/topic/admin-ajax-php-400-error/)
 *  Thread Starter [cmdcmdcmd](https://wordpress.org/support/users/cmdcmdcmd/)
 * (@cmdcmdcmd)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/admin-ajax-php-400-error/#post-10057264)
 * Hi, no sure what you mean here as I am loading the content though the post ID
   and using the .load() function
 * $(document).on( ‘touchstart click’, ‘.portfolio_item’, function( ) {
    $port_holder
   = $(‘.portfolio_holder’); $video_holder = $(‘#video_holder’); $currentitem = 
   $(this);
 *  post_id = $(this).attr(‘data-id’);
    post_link = $(this).attr(‘data-id’), thetitle
   = $(this).attr(‘title’), newcontent = post_link + ” #thevideo”;
 *  $.ajax({
 *  url: ajaxurl,
    type:”GET”, beforeSend: function() {
 *  // animate the thumbnails and add ‘current’ class
 *  $port_holder.find(‘.current’).removeClass(‘current’);
    $currentitem.addClass(‘
   current’);
 *  // make sure the contact section is not visible anymore
    $j(‘.contacts a’).removeClass(‘
   active’); $j(‘#contacts’).fadeOut(300);
 *  $video_holder.find(‘#thevideo’).fadeOut(300, function() {
    this.remove(); });
 *  //hide the menu
    $(‘.main-navigation’).fadeOut(300, function(){ $(‘.loader’).
   show(400); }); $(‘.portfolio_item’).addClass(‘closed’);
 *  },
    success: function( ) {
 *  $(‘.portfolio_item’).addClass(‘open’);
 *  $video_holder.load(newcontent, function() {
    //$video_holder.fitVids(); $(‘.
   portfolio_item’).removeClass(‘closed’); $(‘.video_header’).fadeIn(); //display
   a loader
 *  var theiframe = $(this).find(‘iframe’);
    theiframe.on(‘load’,function(){ $(‘.
   loader’).hide(400); $(this).addClass(‘visible’); });
 *  //CloseHov();
 *  $(‘#thevideo’).on(‘touchstart click’, function(){
    $(‘.portfolio_item’).removeClass(‘
   open’); $video_holder.find(‘#thevideo’).fadeOut(300, function(){ this.remove();
   $(‘.main-navigation’).fadeIn(300); $port_holder.find(‘.current’).removeClass(‘
   current’); });
 *  })
    }); }, complete: function(){
 *  }
    })
 *  })

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