Acquiring JSON data in PhoneGap for Android

Embarking on my journey with PhoneGap and Android, I find myself puzzled by the need to choose a specific platform when it's supposed to be cross-platform. My goal is to call a RESTful service, receive JSON data in response, and display it on the screen. Unfortunately, tutorials for achieving this seem to be scarce. Here is the code snippet I am currently using:

<!DOCTYPE HTML>
<html>
<head>
        <title>JSON Demo</title>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="jquery-1.6.4.js"></script>

        <script type="text/javascript">

$.getJSON('http://MyServerIP/json/GetJobDetails/717/MyKey?callback=?',  {
    success:function(data)
    {
            data = evalJSON(data);
            $('body').append('<strong>X </strong>');
    }, 
    error: function() 
    {
     $('body').append('<strong>Error </strong>'); 
    }
});
        </script>
</head>
<body>
test 10
</body>
</html>

Despite the server confirming that the request was received and data was sent back, I am not seeing any results in the emulator - no success message or error message. Strangely enough, accessing the same URL directly does return the expected data. Why isn't anything showing up in the emulator?

Answer №1

If you're looking for a comprehensive tutorial on Android and jQuery Mobile, check out the official PhoneGAP wiki here:

To solve your issue, ensure that the following line is included in your phonegap app manifest file: < uses-permission android:name="android.permission.INTERNET" >< /uses-permission >

Additionally, don't forget to set the server headers to: 'Access-Control-Allow-Origin: *'

Best of luck on your development journey!

Answer №2

It seemed that the success and error functions were incredibly effective, as demonstrated by this example:

     <script type="text/javascript>

$.getJSON('http://MyServerIP/json/GetJobDetails/717/MyKey?callback=?', function(data)
    {
            data = evalJSON(data);
            $('body').append('<strong>X </strong>');        
});
        </script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to sending both JSON data and form data in a single request using Laravel 9

I am working on a form where I need to input multiple images that will be converted into JSON format. The HTML for my form: create.blade.php <form method="post" action="{{ route('m_announcement.store') }}" enctype="mu ...

When attempting to execute a function within another function in JavaScript, a ReferenceError is triggered

I recently developed a straightforward app that utilizes the Google Drawing Library (https://developers.google.com/maps/documentation/javascript/examples/drawing-tools) to allow users to draw circles on a map. The first circle represents the source locatio ...

Using jQuery to load and parse a JSON file stored on a local system

I am a beginner in scripting languages and recently searched for ways to load and parse JSON files using jQuery. I found helpful resources on Stack Overflow. The JSON file I am working with is called new.json. { "a": [ {"name":"avc"}, ...

What is the best way to generate a "JSON diff" that can be displayed in the JavaScript console?

When working on my Angular project, I frequently encounter the need to compare JSONs in my Karma/Jasmine tests. It would be incredibly useful to have a console output showing what has been added and removed when comparing two structures. For example, ident ...

Storing multiple parameters in AWS SSM using Terraform and a JSON configuration file

In the process of migrating a couple of legacy applications to ec2, we are faced with the challenge of storing multiple application configuration parameters individually. The goal is to have separate parameters for each application. The current approach s ...

Create a JSON by merging two maps of strings

After examining the JSON String that I was expecting, here is what it looks like: { "startDate": "2013-01-01", "columns": "mode , event", "endDate": "2013-02-01", "selection": { "selectionMatch": "123456789012", "selectionT ...

Save a Pandas dataframe as a specialized CSV file containing JSON formatted rows

Currently, in my pandas program I am working on reading a csv file and converting specific columns into json format. For example, the csv file structure is as follows: id_4 col1 col2 .....................................col100 1 43 56 .......... ...

The Postman tool oddly still validates the schema even when the response is incorrect

Below is the schema for a successful response: var responseSchema = { "type": "object", "properties": { "value": { "type": "object", "properties":{ "items": { "type": "array", "items": { ...

Unlocking JSON with various structures using Swift

I am dealing with json data that follows a consistent structure from a nosql database (PK, SK, attributes). The content of the attributes section varies depending on the value of SK. For instance: [ { "PK": "POLL#1544693DF0E88EC-3225- ...

Converting an AngularJS web application into an Android mobile application: A step-by

Looking for guidance on converting an AngularJS application into an Android application. Any assistance in creating this transition would be greatly appreciated. I am specifically interested in incorporating angular routing and angular ui-routing. ...

Filtering arrays using jq at a nested level

I have noticed that all the demo/examples I've come across are filtering on the first level, but my requirement is to perform array filtering with jq on the second level: { "TheArray": [ { "F1": "V11", "F2": "V12", "F3": "V13" ...

Having trouble sending a HTTP Post request to a Web Service from my Android Application

Working on an application that involves using both GET and POST requests to interact with Web Services. While the GET requests are working smoothly, encountering challenges with the POST requests. Have tried two different approaches in the code implementat ...

Searching for specific values within a JSON field that contains an array of objects can be accomplished using Eloquent in Laravel

I am attempting to search within a JSON field using Eloquent, but unfortunately, the search is not yielding any results. This setup is on an Ubuntu server with PostgresSQL, Laravel 5.8, and Apache 2. [{ "value": "1", "label": "number" },{ "va ...

Working through JSON arrays in JavaScript

Here is a JSON example: var user = {"id": "1", "name": "Emily"} If I select "Emily," how can I retrieve the value "1"? I attempted the following code snippet: for (key in user) { if (user.hasOwnProperty(key)) { console.log(key + " = " + use ...

Creating Engaging YouTube Videos Using jQuery and JSON Data

I am struggling with incorporating a click event that will build an SWF player when a thumbnail is clicked from a jSON object. I need assistance in properly setting up the binding between the thumbnails and the SWF player based on the given jSON object. C ...

Verifying JSON array compatibility in PostgreSQL database

I am facing a challenge with a JSONB array in my postgres database. It is structured as follows: { "id" : 22323, "details" : [ { "status" : "stage1", "timestamp" : "201 ...

The initial button click does not display data

I am currently facing an issue with my app when trying to display JSON data retrieved from a PHP web service. The problem occurs when I click the fetch button for the first time and the data does not show up on the labels. After debugging, I noticed that ...

Stop video and audio playback in an android webview

Is there a way to pause audio and video in an Android WebView without disrupting the page rendering? I have tried various methods but haven't found one that successfully pauses both the sound and the video without affecting the WebView. webView.onPau ...

Leveraging OPENJSON in SQL Server Query

I'm facing a challenge with extracting information from a JSON array stored in an SQL Server database. While I understand that the OPENJSON function needs to be used for this task, most examples I've come across focus on declaring a single JSON a ...

Fixing the issue of 'Unrecognized character < in JSON at position 0 at JSON.parse'

I have recently deployed my Angular 6 application on Heroku at . However, upon deploying, I encountered the error message: SyntaxError: Unexpected token < in JSON at position 0 during JSON.parse. I am aware that this error occurs when the response ret ...