title: Update image src using AJAX and PHP function
body: <p>I want to change my image on click function using AJAX in WordPress.
  Here is my code:</p>
  
  <p>JS:</p>
  
  <pre><code>jQuery(".swatchinput label").click(function(){
       var mycolor = jQuery(this).attr("data-option");
       var postid = jQuery(".single-product .product.type-product").attr("data-id");
  
          jQuery.ajax({
              cache: false,
              timeout: 8000,
              url: php_array.admin_ajax,
              type: "POST",
              data: ({ action:'theme_post_vimage', colorimg: mycolor, postvalue: postid}),
  
                    beforeSend: function() {                    
              },
  
              success: function(response){
  
                  var myimageresponse = jQuery( response );
                  jQuery( '.product-image a img' ).attr('src', myimageresponse);                                                      
  
              },
  
              error: function( jqXHR, textStatus, errorThrown ){
                  console.log( 'The following error occured: ' + textStatus, errorThrown );   
              },
  
              complete: function( jqXHR, textStatus ){
              }
  
  
              });
      });
  </code></pre>
  
  <p>And this is my Function in PHP/WordPress:</p>
  
  <pre><code>add_action('wp_ajax_theme_post_vimage','theme_post_vimage_init');
  add_action( 'wp_ajax_nopriv_theme_post_vimage', 'theme_post_vimage_init' );
  function theme_post_vimage_init() { ?&gt;
  &lt;?php
  global $post, $product, $woocommerce;    
  
   $postiID = $_POST['postvalue'];
   $colorname = $_POST['colorimg'];
  
  
  $product = new WC_Product_Variable( $postiID );
  $variations = $product-&gt;get_available_variations();
  foreach ( $variations as $variation ) {
      if($variation['attributes']['attribute_pa_color'] == $colorname) :
      $myimageurl = $variation['image']['url'];
      echo $myimageurl;
      endif;
  }
  ?&gt;
  
  &lt;?php }
  </code></pre>
  
  <p>When I click on my color, this error shows in my browser console:</p>
  
  <pre><code>Uncaught Error: Syntax error, unrecognized expression: http://samsonite.stuntmen.ae/wp-content/uploads/2017/05/PROD_COL_73353_1726_WHEEL-HANDLE-FULL.jpg
  </code></pre>