Solved

Add JavaScript Error Handling

Posted on 2014-12-14
6
99 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
[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
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

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 discusses how to implement server side field validation and display customized error messages to the client.
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)

688 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