Solved

Add JavaScript Error Handling

Posted on 2014-12-14
6
93 Views
Last Modified: 2015-01-07
Hi All,

I have the following code that works well in Chrome, but when I run it on a Blackberry if doesn't work.

Could someone help help adding the on success/error handlers so I can tell whats happening.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>AMS - CRM</title>
		<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
		<script type="text/javascript">
		
		
		// <BUILD INSERT STATEMENT>
			$(document).ready(function(){
				// JSON data url
					var url="https://mydomain.com/json.php";

				$("#status").html("<p>Loading data... please wait</p>");
				

				// <INSERT DATA>
					$.getJSON(url, function(data){
						db.transaction(function (tx) {
							// <create database>
								tx.executeSql('DROP TABLE IF EXISTS CRM');
								tx.executeSql('CREATE TABLE IF NOT EXISTS CRM (id unique, customer, contact)');
							// </create database>
							$.each(data.users, function(i,user){
								var sql_id			= user.id;
								var sql_company		= user.company.replace(/'/g,"\\'").replace(/"/g,'')	// comment out quotes
								var sql_contact		= user.contact.replace(/'/g,"\\'").replace(/"/g,'')	// comment out quotes

								tx.executeSql('INSERT INTO CRM (id, customer, contact) VALUES ('+sql_id+', "'+sql_company+'","'+sql_contact+'")');

							});
						});
						$("#status").html("done");
					});
				// </INSERT DATA>

			});
		// </BUILD INSERT STATEMENT>
		</script>

	</head>
	<body>
	<div id="status"></div>
    </body>
</html>

Open in new window




Many thanks
0
Comment
Question by:detox1978
  • 3
  • 3
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40499068
What version of Blackberry?
0
 
LVL 2

Author Comment

by:detox1978
ID: 40499135
It's a z30, but the code is not browser specific.

I've worked out the issue (certificate needed trusting), but I'd still like to have the error handling on
0
 
LVL 58

Expert Comment

by:Gary
ID: 40499137
Just append your getJSON call

$.getJSON(url, function(data){
    ...
})
.fail(function() { 
    // do whatever for errors
})

Open in new window


http://api.jquery.com/jQuery.ajax/
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 2

Author Comment

by:detox1978
ID: 40514496
Sorry for the late reply.

How do I get it to display more information on what the error is?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40514899
.fail( function(x, status, error) {
        alert("Request Failed -  status: " + status+ ", error: "+error)
});

Open in new window

0
 
LVL 2

Author Closing Comment

by:detox1978
ID: 40535574
thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery, dropdown 4 38
using web browser with BING 40 89
Re-position the objects 7 52
Jquery form submit not working ? 7 20
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
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)

746 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

12 Experts available now in Live!

Get 1:1 Help Now