Is it possible to utilize a variable in the request parameter of a GET REST call in AngularJS?

I am looking to use a parameter's key as a variable whose value can be substituted. The code below illustrates my issue:

js code 

$scope.firstNameAutoSuggestUrl = 'getFirstName';
$scope.paramName = 'fname';
$scope.paramValue = 'sa';

testParamMethod($scope.firstNameAutoSuggestUrl, $scope.paramName, $scope.paramValue);

function testParamMethod(url, paramName, paramValue) {
   $http.get('rest/' + url + '?cd=' + (new Date()).getTime(), { params: { paramName: paramValue } }).success(function(data) {}).error(function(data) {});
}

Actual Request formed

'context root'/rest/getFirstName?cd=1417684294261&paramName=sa

Expected Request

'context root'/rest/getFirstName?cd=1417684294261&fname=sa

Is there any way for the paramName to be substituted with the value I have set?

Answer №1

Give this code a shot, not entirely certain about it,

function  checkParamFunction (url ,paramName ,paramValue)
{    
   var parameterArray = [];
   parameterArray[paramName] = paramValue;

   $http.get('rest/'+url+'?cd='+ (new Date()).getTime(),{params:parameterArray}).success(function(data){ 

   }).error(function(data){

   });
}

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

Personalize the "spirit" component using VueDraggable

I am currently utilizing the library found at: https://github.com/SortableJS/Sortable In my project, I have 2 lists where I can drag one element to the other list. However, when I drag the item, it appears as a clone of the icon. My goal is to have a cust ...

Tips for aligning the timer on a client's webpage with the server

What is the most effective method to synchronize the time displayed on a webpage with the server? My webpage requires that a countdown begins simultaneously for all users and ends at precisely the same time to avoid any user gaining a time advantage. Whi ...

How can I prevent one button from taking precedence over another button even though they have different classes?

I am a newcomer to javascript and jquery and have been grappling with this issue for some time. I have implemented two buttons in a table row - a clear button to clear all forms and a reset button to revert to initial values. However, I am facing a problem ...

Creating Javascript objects inside a loop

I have been attempting to generate objects inside a loop. Check out my code below. <div class="container"> <div class="personDetails"> <input type="text" class="abc" id="Name1"> <input type="text" class="abc" id="Age1"> </div> ...

Struggling with creating a simple AngularJS controller

Apologies if my question seems basic, but I am currently learning about AngularJS controllers. Below is the structure of my project: https://i.sstatic.net/EQOel.png Here is the snippet of my HTML code: <!doctype html> <html ng-app> <hea ...

Automatic Page Refresh Function in Php using Ajax and Javascript

Can I dynamically refresh a specific PHP function using Ajax, Jquery or Javascript every 10 seconds within a designated area on a webpage? Connection.php function TerminalStatus ($IPAddress, $portStatus ) // Handles current terminal status { $connectS ...

Using a personalized function in JQuery

I need to execute a JavaScript function I created after a JQuery event has been triggered. The function in question is called scrambleDot, and I defined it previously like so:var scrambleDot = new function() { //my code }. Here's the attempted implem ...

The Bootstrap navigation bar is experiencing functionality issues when viewed on Chrome mobile browsers

I'm currently testing out the bootstrap 3 navbar feature on my meteor application, but I'm encountering some issues specifically on mobile devices. The problem seems to be that the toggle button is not showing up as expected. Interestingly, it wo ...

Ways to retrieve the child number using JavaScript or PHP

Is there a way to retrieve the child number upon clicking? View screenshot For example, when I click on the X button, I want to remove that specific element. However, this action should only apply to item n2. In order to achieve this, I need to determine ...

The transition from material-ui v3 to v4 results in a redux form Field component error stating 'invalid prop component.'

Since upgrading from material-ui v3 to v4, I am encountering an error with all my <Field> components that have the component prop. Error: Warning: Failed prop type: Invalid prop component supplied to Field. The Field component is imported from im ...

Objects remaining static

I'm currently working on a VueJS component that has the ability to export data into .xlsx format. To achieve this functionality, I am utilizing the json2xls library, which requires an array of objects with identical keys (representing column names) to ...

Tips for retrieving data from a JSON array

I have a JSON object that looks like this: var obj={ "address":{ "addlin1":"", "addlin2":"" }, "name":"sam", "score":[{"maths":"ten", "science":"two", "pass":false }] } Now, when I attempt to m ...

Handling events for components that receive props from various components in a list

In my code, I have a component called PrivateReview which includes event handlers for updating its content. export default function PrivateReview(props) { const classes = useStyles(); const removeReviewAndReload = async () => { await ...

Using mongoose, the findAndModify method returns null when using Promise.all

I'm currently in the process of setting up a nodejs API that is structured with controllers and routes. I am facing an issue where I need to find and update data across multiple collections, then store them as promises to ultimately return a single re ...

Failure to properly evaluate the ID string in Express

I'm currently developing an express app and I am facing an issue with adding a friends list on a user's profile page. The user has an array of friends, which is essentially an ID pointing to another user. However, when comparing this ID to the us ...

Action of the Floater Button in Material UI

I'm currently working with Material UI's floater button component and I am having trouble getting it to open a menu onClick as intended. It is frustrating that there are no example codes available that demonstrate how to make the menu appear when ...

By default, the sidebar is open on desktop devices while closed on mobile devices

I am struggling to figure out how to set my sidebar/navigation content, using Bootstrap, to be expanded by default on desktop and closed by default on mobile with the icon only showing on mobile devices. Despite multiple attempts, I cannot seem to make thi ...

What if I am interested in developing a directive that specifically targets custom elements and attributes?

Suppose I want to create a directive that only matches elements with the attribute amInput[type=dropdown]. How can this be achieved? One possible approach is: .directive('amInput',function () { return { restrict: "E", ...

Tips on extracting variables from JMeter Selenium WebDriver

Currently, I am dealing with a token that is being returned in the body of a web page. WDS.browser.findElement(org.openqa.selenium.By.xpath("//*[contains(@name,'RequestVerificationToken')]")).getText(); This token is what I need to extract: ...

Tips for retrieving data from a concealed input within a div that is being looped through in Angular.js

Currently, I have a controller that sends data to the UI and uses the ng-repeat directive to map them. My next goal is to bind this data with a hidden input form and then send it to another function in the controller when a click event occurs. Any tips on ...