I am experiencing issues with the HTTPClient call not returning accurate JSON data within my Appcelerator Titanium application

Every time I attempt to retrieve information from a JSON file, I encounter an error.

function search(e){
    var url = 'https://www.dotscancun.com/createjson.php?id=100001';
    var xhr = Ti.Network.HTTPClient({
        onerror: function(e){
            Ti.API.info(this.responseText);
            Ti.API.info(this.status);
	    Ti.API.info(e.error);
        },
	timeout: 5000
    });   
    xhr.open('GET',url);
    xhr.send();
    xhr.onload = function(){ 
	var json = JSON.parse(this.responseText); 
	alert(json);
    };
};

This is the code snippet causing the issue.

The specific error message reads as follows:

[LiveView] Client connected
[ERROR] :  TiHTTPClient: (TiHttpClient-8) [1340,1340] HTTP Error (java.io.IOException): 404 : Not Found
[ERROR] :  TiHTTPClient: java.io.IOException: 404 : Not Found
[ERROR] :  TiHTTPClient:    at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1217)
[ERROR] :  TiHTTPClient:    at java.lang.Thread.run(Thread.java:818)

A 404 error indicates that the website does not exist. However, if you directly paste the URL into your browser, it works fine. What could be causing this discrepancy?

Answer №1

The error message mentioned in your query is not pertaining to the JSON query, but rather it is linked to the log output of your Android device. Therefore, you can safely overlook that particular call.

The reason for the coding mistake is as follows:

  • You have not correctly created an HTTPClient object. Instead of using Ti.Network.HTTPClient, you should utilize Ti.Network.createHTTPClient.
  • The onload method must be defined before the open() call.

Below is the accurate code snippet for your inquiry:

function buscar(e){
    var url = 'https://www.dotscancun.com/createjson.php?id=100001';

    var xhr = Ti.Network.createHTTPClient({
        onerror: function(e){
            Ti.API.info(this.responseText);
            Ti.API.info(this.status);
            Ti.API.info(e.error);
        },

        timeout: 5000,

        onload : function(){
            alert(this.responseText);

            // Parse the response for future utilization
            var tempJSON = JSON.parse(this.responseText);
        }
    });

    xhr.open('GET',url);
    xhr.send();
}

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

Setting up StrongLoop LoopBack MongoDB datasource for successful deployment on Heroku

Currently, I am utilizing LoopBack version 1.6 and have a local mongoDB server operational for development purposes with the following datasource configuration: "mongodb": { "defaultForType": "mongodb", "connector": "loopback-connector-mongodb", ...

Trouble with jQuery event.keyCode in detecting alphanumeric characters

I recently developed a script that is supposed to detect the key the user clicks and perform an action based on whether it is alphanumeric. However, I am encountering an issue as the script does not seem to be working as expected, and I am not receiving an ...

Show concealed content for individuals who do not have javascript enabled

One of the challenges I faced was creating a form with a hidden div section that only appears when a specific element is selected from a list. To achieve this, I utilized CSS to set the display property of the div to 'none' and then used jQuery t ...

Can you provide a require statement that is the equivalent of this import statement?

Looking to transition a few files from utilizing import to using require in order to eliminate the need for Babel. One of the import statements appears like this: import React, { Component } from 'react'; How can I change it to a require state ...

How can we extract word array in Python that works like CryptoJS.enc.Hex.parse(hash)?

Is there a method in Python to convert a hash into a word array similar to how it's done in JavaScript? In JavaScript using CryptoJS, you can achieve this by using: CryptoJS.enc.Hex.parse(hash), which will provide the word array. I've searched ...

Is there a way to conceal the headers during an ajax request?

I'm currently exploring APIs using jQuery and Ajax. To set the header of Ajax, I typically use code similar to this: headers: { "My-First-Header":"first value", "My-Second-Header":"second value" }, I am working on a basic school project and ...

async.series: flexible number of functions

Hello everyone, I'm currently working with Node.js (Express) and MongoDB (mongooseJS). My goal is to create a series of async functions that query the database in the right order. Here is my question: How do I go about creating a variable number of a ...

Exploring the World of Github on Windows: Understanding the 'master' and 'gh-pages' Branches

I have developed a simple jQuery plugin and uploaded it to Github. I am using both the Github website and Github for Windows to manage this project. However, when I try to include the .js or .css files from Github using the Raw links, my browser fails due ...

Combine various choices into a select dropdown

I am facing an issue with an ajax call in codeigniter where the response always consists of two values: team_id1 and team_id2. Instead of displaying them as separate values like value="1" and value="2", I want to join them together as value="1:2". I have ...

An effective method for linking a value from one ng-model to another is by identifying and matching a specific string

I have been tasked with binding a value to one model based on the content of another model when it contains a string that starts with "https". For instance, there are two text fields each associated with a different model. <input type="text" ng-model= ...

Having trouble opening a JPEG file that was generated using the Writefile Api in Ionic-Cordova

Currently, I am using the writeFile API to create a JPEG image. The process is successful and the image is stored in the directory as expected. However, when I try to open the file manually from the directory, I encounter an error message saying "Oops! Cou ...

`Modified regions determined by cursor location`

I am working with a split layout featuring two columns, and I need the ability to make each column separately scrollable. Due to using a specialized scroll-to function, I cannot use overflow-y: scroll; or overflow: auto;. I am looking for alternative solut ...

Converting to REST API on Node.js for handling POST requests with JSON body

I'm in a bit of a pickle. I've been sending JSON data to my Node server using RESTify for its API, but I can't seem to extract the req.body.name from the posted data. The JSON body contains keys like name, date, address, email, etc. All I n ...

Utilize React-markdown to interpret subscript text in markdown format

I tried to create subscript text in an .md file using the following syntax: x_i x~i~ Unfortunately, react-markdown did not interpret this as subscript. After some research, I discovered the package remark-sub-super and implemented it with the plugin ...

Guide on using JavaScript to implement the universal CSS selector

One technique I frequently employ is using the CSS universal selector to reset the dimensions in my HTML document: * { border: 0; margin: 0; padding: 0; } I wonder if a similar approach can be achieved with JavaScript as well? When it come ...

Creating JSON strings from any data type in C#

My current setup involves using the GET method (MCV4 / WEB-API/ VS 2010). I am looking to return a response string in JSON format. If I have any string and want to convert it to JSON for the response, how can this be achieved: string s = "{\"one&bs ...

Develop a real-time preview of the form inputs

While working on a multistep form, I am exploring the idea of creating a live preview that shows values entered into different input fields, text areas, and radio buttons. Currently, I have successfully built the form and made some progress using the foll ...

Mesh with custom lighting effects in Three.js using specific light sources

In my current scene, I have various objects, including spheres that I want to be illuminated by pink and blue lights. However, there is also a tube geometry that should only be affected by a white light, without picking up the pink and blue colors. To ill ...

Recursive function: the process of storing numerous values in variables

There is a code snippet showcasing a recursive function designed to take a number, for example n=5, and produce an array counting down from n to 1 (i.e., [5,4,3,2,1]). The point of confusion arises just before the numbers/values of n are added to countArr ...

The transition effect of changing opacity from 0 to 1 is not functioning properly in Firefox

Having some trouble with this animation not working in Firefox. I'm triggering the animation using JavaScript after a delay like so: document.getElementById('my_id').style.webkitAnimationPlayState = "running"; I've also attempted: s ...