Solved

My First jQuery Experiment Works in Chrome but not IE11 and Safari.  Any idea why?

Posted on 2014-04-01
5
1,872 Views
Last Modified: 2014-04-03
I've got my first page using jQuery to work perfectly in Chrome, however it doesn't work in IE11.  I'm attaching the relevant code below.  Any idea what I'm doing wrong?

Also, Do any sites exist where I could plug in my code and test whether it will work in various browsers?  That would sure save a lot of time.

(The page in question is located at www.pbkplus.com)

Main page
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js"></script> <script type="text/javascript" src="http://www.pbkplus.com//cl/StoreNumber_4761/home/js/pbkpluscom_jquerytest.js"></script> <link rel="stylesheet" type="text/css" href="http://www.pbkplus.com//cl/StoreNumber_4761/home/css/pbkpluscom_jquerytest.css"></link><content></content>

Open in new window


External JavaScript file (located in /js subfolder)
/*
$(function() {
	$('h1').addClass('standout');
});
*/
$.ajax({
	type: "GET",
	url: "http://www.pbkplus.com/home/xml/pbkpluscom_jquerytest.xml",
	dataType: "xml",
	success: function(xml) {
		$(xml).find('story').each(function(){
			$('<h3>').html( $('headline', this).html() ).appendTo('content');
			$('<p>').html( $('content', this).html() ).appendTo('content');
			});
	}
});

Open in new window


CSS File (located in /css subfolder)
.standout {
  color:red;
  text-align:left;
  font-size:20pt;
}

.imgfloatr {
	float: right; 
	margin: 0px 0px 15px 15px;
}

.imgfloatl {
	float: left; 
	margin: 0px 15px 15px 0px;
}

Open in new window


XML File (locate in /xml subfolder)
<?xml version="1.0" encoding="UTF-8"?>
<stories>
  <story>
    <headline>Buy Kindles, eBooks, and Accessories at Paperbacks Plus!</headline>
    <content>
		<div class='imgfloatl'><iframe width="125" height="125" scrolling="no" border="0" marginwidth="0" frameborder="0" style="border: none;" src="http://rcm-na.amazon-adsystem.com/e/cm?t=soulforcbook-20&amp;o=1&amp;p=21&amp;l=ur1&amp;category=kindle&amp;banner=1PYTZGNDY2ZTANQ341R2&amp;f=ifr"></iframe></div>
		Paperbacks Plus has partnered with Amazon.com to offer Kindle tablets, readers, accessories, eBooks, and other related products directly to our customers.  By <a href='http://www.pbkplus.com/?page=shop/disp&amp;pid=page_kindlestore'>purchasing your Kindle products here</a> you not only get access to Amazon's vast product catalog, you also help support your local bookseller and keep low-cost new and used books available in your local community.  If you don't see what you want here, please contact us and we'll add the product as quickly as possible.  If you would like to see our line of Kindle products in person, please <a href='http://www.pbkplus.com/?page=shop/disp&amp;pid=page_contact'>visit our store</a> during regular business hours and we'll be glad to demonstrate them for you.  Thank you for your support.
    </content>
  </story>
 <story>
    <headline>Paperbacks Plus now sells and supports the Kobo eReader</headline>
    <content>
		<div class='imgfloatl'><a href="http://click.linksynergy.com/fs-bin/click?id=hYU0qM*5sdg&amp;offerid=314164.187&amp;subid=0&amp;type=4"><img border="0" alt="Kobo Devices" src="http://ad.linksynergy.com/fs-bin/show?id=hYU0qM*5sdg&amp;bids=314164.187&amp;subid=0&amp;type=4&amp;gridnum=4" /></a></div>	
		To better serve our readers who want to continue supporting local independent booksellers but who want the convenience of an eReader, Paperbacks Plus is now an official Kobo Affiliate. Kobo is the manufacturer of a line of eReaders comparable in functionality to the Kindle and Nook readers but available through independent retailers. Watch this space for exciting information to come about the various Kobo eReader platforms and the millions of eBooks available for them - right here at pbkplus.com. As always, feel free to <a href='http://www.pbkplus.com/?page=shop/disp&amp;pid=page_contact'>contact us</a> if you have any questions about getting started with Kobo.
    </content>
  </story>  
  <story>
    <headline>Prioritize Your Favorite Authors</headline>
    <content>
		As we build our online inventory we are starting with our most popular authors. If you would like us to prioritize your favorites, please <a href='http://www.pbkplus.com/?page=shop/disp&amp;pid=page_contact'>contact us</a> and let us know who they are. We will then inventory everything we have by those authors so that you'll be able to see our complete collection whenever you like.
    </content>
  </story>
</stories>

Open in new window

0
Comment
Question by:penlandt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Expert Comment

by:Snarf0001
ID: 39970868
For starters, look at this line in the header:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"">

Open in new window


You've got a double quotation mark at the end, which is throwing off all the rest of the markup.
Chrome is nice enough to fix that for you, other browsers aren't.  Try removing that and check for other similar issues and see if that fixes your problem.
0
 
LVL 1

Author Comment

by:penlandt
ID: 39970918
Thanks Snarf0001.  That part appears to be hardcoded by the template provider - not something I can change.  (I will notify them and ask them to fix it.)  I'm pretty sure that isn't the cause of the problem though because it was that way before I started using jQuery and the previous version of the page loaded without any problems.
0
 
LVL 40

Expert Comment

by:Eoin OSullivan
ID: 39971547
IE11 has its own developer tools which include a debugger - you can simply open this and see what is causing the Javascript error
Developer Tools
http://msdn.microsoft.com/en-us/library/bg182326(v=vs.85).aspx
The Debugger
http://msdn.microsoft.com/en-us/library/dn255007(v=vs.85).aspx
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39971832
XML is XML - not HTML. If you want to get the info from your XML file then usually you use text(), not html():

$('headline', this).text()

Open in new window

If you have HTML in your XML file, then you need to change the dataType to html:

$.ajax({
	type: "GET",
	url: "http://www.pbkplus.com/home/xml/pbkpluscom_jquerytest.xml",
	dataType: "html",
        ...
});

Open in new window

0
 
LVL 1

Author Comment

by:penlandt
ID: 39976585
Thank you Chris, that solved the problem.  I changed my datatype to "html" but kept $('headline', this).text() the way it is (with 'html' instead of 'text') because some of my elements contain html tags.

I appreciate the help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question