Title: Ajax response handler breaks Javascript
Last modified: August 30, 2016

---

# Ajax response handler breaks Javascript

 *  [Martien](https://wordpress.org/support/users/martien-van-lent/)
 * (@martien-van-lent)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/ajax-response-handler-breaks-javascript/)
 * The ajax response handler does $data = $(documentHtml(data)).
 * However, when using $(html_string), jQuery sees every ‘<‘ sign in the string 
   as a HTML opening tag, therefore the ‘less then’ sign breaks javascript code.
 * Solution:
 *     ```
       var el		= document.createElement('html').innerHTML;
       el.innerHTML	= documentHtml(data);
       var $data	= $(el);
       ```
   
 * Cheers, Martien
 * [https://wordpress.org/plugins/ajaxify-wordpress-site/](https://wordpress.org/plugins/ajaxify-wordpress-site/)

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

 *  Thread Starter [Martien](https://wordpress.org/support/users/martien-van-lent/)
 * (@martien-van-lent)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/ajax-response-handler-breaks-javascript/#post-6668528)
 * Solution should be:
 *     ```
       var el		= "";
       el.innerHTML	= documentHtml(data);
       var $data	= $(el);
       ```
   
 * Sorry, Martien
 *  Thread Starter [Martien](https://wordpress.org/support/users/martien-van-lent/)
 * (@martien-van-lent)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/ajax-response-handler-breaks-javascript/#post-6668539)
 * Oops, wrong again. It appears there’s something wrong with the HTML Helper function
   documentHtml() also.
 * Fetch the scripts from the raw ajax response data does work:
 *     ```
       // Fetch the scripts
       var el = document.createElement('html');
       el.innerHTML=data;
       $scripts = $(el).find('#' + aws_data['container_id'] + ' script');
       if ( $scripts.length ) $dataBody.find('#document-script').detach();
       ```
   

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

The topic ‘Ajax response handler breaks Javascript’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/ajaxify-wordpress-site.svg)
 * [Ajaxify Wordpress Site(AWS)](https://wordpress.org/plugins/ajaxify-wordpress-site/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ajaxify-wordpress-site/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ajaxify-wordpress-site/)
 * [Active Topics](https://wordpress.org/support/plugin/ajaxify-wordpress-site/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ajaxify-wordpress-site/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ajaxify-wordpress-site/reviews/)

## Tags

 * [aws](https://wordpress.org/support/topic-tag/aws/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 2 replies
 * 1 participant
 * Last reply from: [Martien](https://wordpress.org/support/users/martien-van-lent/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/ajax-response-handler-breaks-javascript/#post-6668539)
 * Status: not resolved