Solved

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

Posted on 2014-04-01
5
1,824 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
5 Comments
 
LVL 22

Expert Comment

by:Snarf0001
Comment Utility
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
Comment Utility
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 39

Expert Comment

by:Eoin OSullivan
Comment Utility
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 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now