detox1978
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.
Many thanks
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>
Many thanks
What version of Blackberry?
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
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
http://api.jquery.com/jQuery.ajax/
$.getJSON(url, function(data){
...
})
.fail(function() {
// do whatever for errors
})
http://api.jquery.com/jQuery.ajax/
ASKER
Sorry for the late reply.
How do I get it to display more information on what the error is?
How do I get it to display more information on what the error is?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks