Implementing AngularJS with varied parameters and functions

Perhaps this issue isn't related to AngularJS, but I'm still new to it and struggling to figure out what's going wrong. Can someone please point me in the right direction? I've been working on this for over 3 hours and it's really getting me down. :-(

I have a function where I pass my SQL queries along with other parameters. I want this function to be as flexible as possible.

prepareQuery('SELECT name FROM Lists WHERE id=(?)', [$scope.listId], listnameResultHandler(), defaultErrorHandler());
prepareQuery('SELECT * FROM Products', [], defaultResultHandler(), defaultErrorHandler());

To break this down:

  1. Parameter: SQL query
  2. Parameter: values bound to the query
  3. Parameter: the success function if the query is successful
  4. Parameter: the error function if there is a problem

Now, here is the prepareQuery function:

function prepareQuery(query, params, successHandler, errorHandler) {
    $scope.db.transaction(function(tx){
        tx.executeSql(query, params, successHandler, errorHandler);      
    }, errorCB); 
}

The issue I'm facing is that I always receive a response from the defaultErrorHandler().

function defaultErrorHandler(err) {
  alert("Error processing SQL: " + err.code);
}

And the error message always shows as: undefined.

Answer №1

section, it is crucial to utilize function pointers instead of directly calling functions. Avoid including brackets after the function name defaultResultHandler.
prepareQuery('SELECT name FROM Lists WHERE id=(?)', [$scope.listId], listnameResultHandler, defaultErrorHandler);
prepareQuery('SELECT * FROM Products', [], defaultResultHandler, defaultErrorHandler);

Answer №2

It seems that the issue arises from mistakenly INVOKING the error-handler instead of simply passing it as an argument to the prepareQuery function. By directly calling it without any parameters, the error itself becomes undefined. You should modify your code like this:

prepareQuery('SELECT name FROM Items WHERE id=(?)', [$scope.itemId], itemNameResultHandler, defaultErrorHandler);
prepareQuery('SELECT * FROM Products', [], defaultResultHandler, defaultErrorHandler);

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

Utilize Server Side Includes in your JavaScript code

When the query string is parsed, a specific section of code SSI is included in the footer page. Here are some examples of query strings: ?headId=520&genderType=2 ?headId=600&genderType=1 function GetQueryStringParams(sParam){ var sPageURL ...

Minimize the number of axios requests made every time a Vue component is displayed

I am relatively new to Vue, so please bear with me as I may not have all the knowledge in this area. Within one of my child components (Product_Collection.vue), I am making an axios request to retrieve products from my Shopify store using their GraphQL ...

Showing information on a grid using ejs and express

My goal is to display news articles using the NewsAPI in a grid format, with each grid item randomized in appearance. However, I'm encountering an issue where I only receive one instance of data from express for each loop iteration, resulting in grids ...

retrieve file through an ajax call

When I click on a button, I want to send an AJAX download request. I attempted it like this: Here is my JavaScript code: var xhr = new XMLHttpRequest(); xhr.open("GET", "download.php"); xhr.send(); In the download.php file: <? header("Cache-Control: ...

What is the best way to ensure my button displays the complete description of a single country after showcasing all the countries?

I have designed a search feature for countries and I am looking to add a button next to the country names that will trigger one of my components responsible for displaying detailed information about the country. Currently, the details are shown only when t ...

Enhancing web development with jQuery: the power of adding and removing

I'm currently working on creating a default tab that can switch classes when another tab is clicked. This is the HTML code I have so far: <div id="rightWrap"> <div id="headStep"><span class="titleSub">Workers</span></ ...

Strategies for identifying DOM modifications during acceptance testing using Selenium and Codeception

Currently, I am in the process of creating an acceptance test for an application developed using Angular. This involves utilizing the Codeception testing framework in conjunction with Selenium. The main objective of the test is to input text into a speci ...

Utilizing data in mongoose: A beginner's guide

I have two database models: User and Conversations. The User model has the following schema: const userSchema = mongoose.Schema({ username: String, logo: String, ..... }) and the Conversation schema is as follows: const conversationSchema = mongo ...

Evaluate the Javascript string and save the output

My challenge involves receiving JavaScript as a string that needs to be executed and compared to a specific output. Currently, I am utilizing the eval() function for this task, but I am open to alternatives. The execution takes place on the client side wit ...

How to dynamically apply the orderBy filter in AngularJS

Attempting to input ordering criteria from a text box and dynamically order the content. The current code is functioning properly, but when attempting to change: orderBy:'age' to orderBy:'{{criteria}}' the functionality breaks. Her ...

Error: The prop type validation failed because a `value` prop was provided to a form field in React-Bootstrap-Typehead component

I am currently using the bootstrap-typehead package from https://github.com/ericgio/react-bootstrap-typeahead and struggling to understand why it's causing issues. Could someone help me identify what's wrong with this code that's triggering ...

Organize the array based on the grandchild's value

Consider this scenario: I have a collection of objects, where each object contains another collection of objects. The structure is as follows: [ { "dislikes": [ { "createDate": { "date": 11, ...

One more time: Utilizing AJAX to save the outcome in a variable with the help of callback (undefined)

I am facing a common problem and despite my efforts, I cannot seem to resolve it. The code snippet I have provided below is causing me trouble: function get_network_from_database(callback) { $.ajax({ type: "POST", url: "load_network.ph ...

What is the best approach to reverse an integer or non-integer value in SQL Server 2008?

Here is a specific integer value: 50326518 I am looking to convert it into reverse order, but with the output format as follows: 18653250 When using the reverse() function, I receive 81562305 as the result. However, my desired output is 18653250. Any ...

Is it possible to automatically access the most recent Beta build through package.json and npm?

We are currently working on a project that has a specific dependency requirement for the latest beta build from an npm library. However, there are also -dev builds within the library. For instance, in the "x-library" there might be versions like: "1.2.3- ...

How can I invoke a personalized function in angularjs from HTML?

One way to organize methods within js controllers is by defining them separately like this: angular.module('test').controller('mycontroller', mycontroller); function mycontroller() { //do something }; function ...

Implementing Ui-Select: Enhancing functionality with a static footer directive

I am currently working on Ui-Select. My current task is to add a static button or text with a link as a footer inside the ui-select, displaying the level of match with the entered text. I am facing difficulties in getting my footer directive to only show ...

retrieve dynamically generated content following successful login using cURL

It's common knowledge that curl doesn't process JavaScript, it only fetches static HTML. This is why a simple curl command won't suffice for my needs. I'm not well-versed in PHP, still new to this field. From what I've gathered so ...

a service that utilizes $http to communicate with controllers

My situation involves multiple controllers that rely on my custom service which uses $http. To tackle this issue, I implemented the following solution: .service('getDB', function($http){ return { fn: function(){ return $http({ ...

Optimal guidelines for logging in

After successfully creating a website using HTML, CSS, and JavaScript, I am now looking to implement a login feature to provide privacy for certain users. I have noticed that some developers use PHP, while others use JS or Node.js for this purpose. However ...