Sending parameters and obtaining results with AngularJS

I'm encountering an issue. I need to trigger a function with arguments and receive results upon clicking on a .md-button with ng-click.

Here's the HTML:

<md-button class="md-raised md-primary" ng-click="setreg.register({{reg.email}},{{reg.pass1}},{{reg.pass2}},{{reg.name}});" style="width: 100%">
                Register
            </md-button>
            <div>
                <label>Result :</label>{{setreg.SetRegister}}
            </div>

JS

var app = angular.module("demoApp", ["ngMaterial", "ngMessages"]);

app.controller("SetRegister", ["$http", function ($http) {
var result = this;
var dbName = "0";
var dbUserName = "0";
var dbPassword = "0";
var dbUrl = "0";

var register = function (email, pass1, pass2, name) {
    if (pass1 !== pass2) {
        result.SetRegister = "[{\"result\":\"Password verification failed\"}]";
    } else {
        var query = "INSERT INTO users (FullName,email,Pass) VALUES ('" + name + "','" + email + "','" + pass1 + "')";
        var url = "http://37.247.113.31:20083/Services/SetData.aspx?dbUrl=" + dbUrl + "&dbUName=" + dbUserName + "&dbPass=" + dbPassword + "&dbDbName=" + dbName + "&query=" + query;
        $http.get(url).success(function (data) { result.SetRegister = data; });
        $http.get(url).error(alert("ERROR"));
    }
};
result.SetRegister = register;
}]);

Can you spot any issues with this code? How would you go about fixing it? Sincerely

Answer №1

I have successfully resolved this issue. Thank you to everyone who provided answers.

JS

app.controller("SetRegister", ["$http", function ($http) {
var result = this;
var dbName = "0";
var dbUserName = "0";
var dbPassword = "0";
var dbUrl = "0";


var register = function (email, pass1, pass2, name) {
    if (pass1 !== pass2) {
        result.SetRegister = "[{\"result\":\"Password verification failed\"}]";
    } else {
        var query = "INSERT INTO users (FullName,email,Pass) VALUES ('" + name + "','" + email + "','" + pass1 + "')";
        var url = "http://37.247.113.31:20083/Services/SetData.aspx?dbUrl=" + dbUrl + "&dbUName=" + dbUserName + "&dbPass=" + dbPassword + "&dbDbName=" + dbName + "&query=" + query;
        $http.get(url).success(function(data) { result.SetRegister = data; });
        $http.get(url).error(function (data) { result.SetRegister = data; });
    }
};
result.SetRegister = register;

}]);

HTML

<md-button class="md-raised md-primary" ng-click="setreg.SetRegister(reg.email,reg.pass1,reg.pass2,reg.name);" style="width: 100%">

This function sends a request query and receives either an OK or FAIL response message. The service is responsible for inserting data into the database.

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

What is the best way to merge different Vue JS instances (each linked to different html divs) into one cohesive unit using Vue

Essentially, I have a scenario where I've created two HTML divs named vueapp1 and vueapp2. Both of these divs serve the same purpose of displaying information and are linked to their individual Vue instances for extracting JSON data and presenting it. ...

The Heatmaps.js script encountered an Uncaught ReferenceError

I am currently utilizing the heatmaps.js library along with the Google Maps API to showcase a map with a heatmap overlay. So far, I have successfully displayed the map and retrieved the necessary data from the database. However, I'm encountering an is ...

Retrieve information from a JSON key-value pair with the help of AngularJS

Is there a way in Angular's ngRepeat to extract a specific value from a JSON Array based on its key? I am working with the following JSON structure and would like to display the "Name 2" value for each object. { "Items": [ { ... "At ...

How to avoid redundant data when iterating over an array with Geofire and Firebase?

Could you please review my code snippet below? var posts = PostsData.getPosts(); var postFunc = function(key) { return posts[key]; } $scope.$watch($scope.active, function() { $timeout(function() { var markers = []; for ...

Implementing Dynamic Styling Using Parent Component in React Native

I am facing an issue with a <Text> component that is receiving a style through props... TextFile.js: <Text style={styles.text}> This is a line of text and this might be a second line </Text> screenFile.js: <View style={styles.v ...

"Encountering issues with Node.js while loading required modules

Having created an API utilizing hummus.js, I encountered a problem after uploading it to my server (Ubuntu Root + Plesk Onyx) and performing an npm install on my package.json. Despite receiving a "Success" status message during the installation process, my ...

having trouble parsing JSON data

Recently, I decided to experiment with JSON and utilized json_encode to generate a JSON object structured as shown below: [{ "timestamp": "12\/16\/2013 0:00", "curr_property": "7211", "curr_property_cost": "123", "day_pro ...

Sharing filtered data between controllers in AngularJS is a powerful feature to enhance data

One common topic of discussion is how to share data between controllers. In my case, I addressed this issue by creating a factory that contains functions for calling our API and retrieving the data we need. angular.factory('polygonService', [&ap ...

Issue with October CMS: Radio button selection triggers an Ajax call, but clicking twice in quick succession causes the content

I am currently utilizing October CMS and materializecss to develop a form with options on one of my pages. The form functions correctly as it dynamically loads content when different options are clicked. However, I have identified a problem where clicking ...

What causes scope to be undefined in Angular?

Using ionic to develop a hybrid app has been a smooth experience, especially with android! This is my login HTML: <body ng-app="starter"> <head> <script src="phonegap.js"></script> </head> <ion-header-ba ...

File Upload yields a result of 'undefined'

Currently, I am utilizing Express File Upload. When attempting to send a post request to it, the error-handler returns an error indicating that no files were found. Upon logging console.log(req.files), it shows as undefined, causing the error to be sent ba ...

Printing an array from JavaScript to an EJS template: Tips and Tricks

I'm currently working on a database-driven website that focuses on searching through people's profiles. When attempting to display information from a database query, I am encountering the issue of receiving [object Object]. Below are snippets o ...

What is the best way to update and override multiple nested NPM dependencies with various versions?

Apologies for not being fluent in English Here is my NPM dependency: dependency tree +-- <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c1e090d0f184108091a4105021f1c090f18031e2c5d4255425c">[email protected]</a> ...

What is the best way to extract data from an NSURLRequest configuration object?

I am trying to send POST requests from an Angular web build within an iOS app to the native layer using some JSON data to enable native functionality. The challenge arises from using the older UIWebView due to Angular requirements, which leads me to levera ...

Creating an application for inputting data by utilizing angular material and javascript

I am looking to create an application using Angular Material Design, AngularJS (in HTML), and JavaScript. The application should take input such as name, place, phone number, and email, and once submitted, it should be stored in a table below. You can fin ...

Tips for managing and modifying information with a dropdownlist in asp.net core mvc and angular js

In my asp.net core MVC project, I am incorporating AngularJs to manage two dropdown lists and a textbox. While the textbox functionality for saving and editing data works well, I am facing issues with resetting the dropdown lists after posting data and not ...

How to Redirect a Webpage to the Same Tab in ASP.NET

I am currently using an asp.net hyperlink control to direct users to a web URL when the hyperlink is clicked. My goal is for the user to open a new tab, rather than a new window, when they click the hyperlink. If the user clicks the link again, I want th ...

Is it normal for the protractor cucumber tests to pass without observing any browser interactions taking place?

Having recently started using protractor cucumber, I have created the following feature. Upon launching protractor protractor.conf.js, the browser opens and immediately closes, displaying that my tests have passed. Is this the expected testing behavior? Sh ...

Tips for extracting value from PHP and transferring it to a jQuery function

I am trying to calculate the distance between two airports and pass this value back to a jQuery function to use it in further calculations. I'm unsure of where I went wrong? HTML: The 'dept' and 'dest' inputs fetch airport informa ...

AngularJS doesn't cooperate well with square brackets in form field names

While using AngularJS for validation within a Symfony2 form, I encountered an issue with the naming of the form field generated by Symfony2 as "license[domain]". The validation process functions correctly; however, AngularJS struggles to handle the braces ...