I am writing an app (not web app) for mobile devices using icenium which uses javascript etc rather than its native language.
The app displays rows from a data base, displaying events. The user then clicks on an event which displays more information on the event, however I am having trouble calling the ajax from a js function as below:
function showSingle(itemId){
//document.write(itemId);
$('#output').fadeOut();
$('#single').fadeIn("fast");
$.ajax({
url: 'http://dev.123456789.co.uk/getSingle.php',
dataType: 'jsonp',
data: { dbId: itemId },
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status){
var linkedPageSingle = '<h2>'+item.eventName+'</h2>'
+ '<p>Description: '+item.description+'</p><p>Type: '
+ item.type+'</p><p id="pageid">'+item.id+'</p>';
$('#single').append(linkedPageSingle);
// pageId = $('#pageid').html();
$('#single').text('debugdebug.');
},
error: function(){
$('#single').text('There was an error loading the data.');
}
});
}
This does not return any data, it doesn't even return $('#single').text('debugdebug.'); so there must be a problem with the ajax call? Also
error: function(){
$('#single').text('There was an error loading the data.');
}
Is not outputted. Can you spot an error in this? The call to the function is here:
var linkedPage = '<h2><a href="#" onClick="showSingle('+item.id+')">'+item.eventName+'</a></h2>'
+ '<p>Description: '+item.description+'</p><p>Type: '
+ item.type+'</p><p id="pageid">'+item.id+'</p>';
Which is in a document.ready section of the page, inside an ajax method (which works).
getSingle.php:
<?php
/*
* Script to connect to database and pull out information for app!
*/
include 'connect.php';
$dbId = $_POST['dbId'];
$query = mysql_query("SELECT * FROM calTest where `id`='$dbId'");
$records = array();
while($row = mysql_fetch_assoc($query)) {
$records[] = $row;
}
echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
?>
Can't see where I have gone wrong, Thanks!