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
Solved

Add JavaScript Error Handling

Posted on 2014-12-14
6
96 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)
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…

860 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