Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

Add JavaScript Error Handling

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
JavaScriptjQueryAJAX

Avatar of undefined
Last Comment
detox1978
Avatar of Gary
Gary
Flag of Ireland image

What version of Blackberry?
Avatar of detox1978
detox1978
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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
Avatar of Gary
Gary
Flag of Ireland image

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/
Avatar of detox1978
detox1978
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Sorry for the late reply.

How do I get it to display more information on what the error is?
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of detox1978
detox1978
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

thanks
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo