Link to home
Start Free TrialLog in
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
Avatar of Gary
Gary
Flag of Ireland image

What version of Blackberry?
Avatar of detox1978

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
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/
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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks