Tips for retrieving the li value from localStorage

This is a snippet from my coding project.

function getStudentList() {
    $.getJSON('http://mydomain.com/getStudents.php?jsoncallback=?', function(data) {
        $('#studentList li').remove();
        $('#load').hide();
        
        $.each(data, function(index, student) {
            $('#studentList').append('<li><a href="student_detail.html?user_name=' + student.data.user_name + '">' +
                    '<h4>' + student.data.user_name + '</h4>' +
                    '<p>' + student.data.role + '</p>' +
                    '</a></li>');
        });
        $('#studentList').listview('refresh');
    });
}

I have heard that PhoneGap may not support URL formats like student_detail.html?user_name=XXXX. Therefore, I am considering using localStorage for storing the selected student's details. Is this a valid approach? How can I save the value of the chosen student's username?

var id = $("#id").val();
window.localStorage["id"] = id;

I'm unsure how to create a specific #id inside $.each loop.

Answer №1

PhoneGap interprets relative URLs as if they were local files (file://) included within the project.

If student_detail.html is located on a server, you should use a complete URL such as

http://mydomain.com/student_detail.html?user_name=...

It is also important to make sure that http://mydomain.com is allowed in the PhoneGap project whitelist, as explained in

To assign an ID to each li, simply include it in your template:

... .append('<li id="' + student.data.user_name + '"> ...')

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

How do I use props to enable and conceal elements like lists, buttons, and images?

Check out this unique component: <ReusedHeader H1headerGray="text here... " H2headerRed="text2 here ! " pheader="p1" getStarted="button text1" hrefab="button url 1" whatWeDo="button text ...

Creating engaging animations with styled components in ReactJs

I have embarked on the journey of crafting a testimonial section that bears resemblance to the testimonials displayed on the website www.runway.com. Leveraging styled-components, I've made progress in piling up the cards at the center of the screen, w ...

Running JSON in Selenium framework

Can someone help me with the simplest method to implement JSON in a Selenium test? For instance, I am looking to send a POST request with { "UserId":"234234" } and verify the response. Right now, I'm manually testing using the Advanced REST client Chr ...

If there is no data defined, then it is necessary for at least one attribute to be present in the

I am encountering an issue while attempting to utilize Google Cloud's Pub/Sub API to send messages to topic subscribers. The error message I am receiving is "If data is undefined, at least one attribute must be present.". My intention is to integrate ...

Changing the Direction of News Ticker Movement from Right to Left

I need to switch the news ticker movement direction from right to left to left to right because I will be using Arabic language, so it is crucial to change the movement direction. Despite trying for several days, I have been unable to find a solution. HTM ...

Trigger Azure Linked Template Default Value

Having an issue with Linked Templates in Azure ARM templates. Struggling to utilize the default value of a sub template while still keeping a reference to a parameter in the parent template. parent.json ... parameters: { foo: { type: "string" } } ...

"Encountered a floating-point issue when trying to read an Excel file with

When a user uploads an Excel file that contains decimal, string, and Unicode characters, I am encountering an issue with floating point errors when reading certain decimal values. For instance, a number like 0.15 is being read as 0.150000000002 in some c ...

Retrieving information from an API using JSON and then combining two separate objects into one row within an Array Adapter

Here is some code that fetches data from an API and displays it in a List View. The goal is to show both the "rate" and the corresponding "name" on the same row, making it more user-friendly for the users. The AsyncTask provided below successfully retriev ...

Unable to display any content from JSON data in Spinner despite no errors being present

It seems like the issue I'm encountering is due to the UI drawing my layout first, which includes a spinner before fetching data from the backend. I need to figure out how to block it and wait for the data retrieval process to complete before populati ...

What is the importance of manually merging geometries?

After exploring the performance implications of merged geometries, I've discovered that the GPU generates draw calls for all shared geometries combined with materials (or maybe just the material count). This has led me to wonder why developers are req ...

Disabling eslint does not prevent errors from occurring for the unicorn/filename-case rule

I have a file called payment-shipping.tsx and eslint is throwing an error Filename is not in camel case. Rename it to 'paymentShipping.tsx' unicorn/filename-case However, the file needs to be in kebab case since it's a next.js page that s ...

Using TypeScript's union type to address compatibility issues

Below is a small example I've created to illustrate my problem: interface testType { id: number } let t: testType[] = [{ id: 1 }] t = t.map(item => ({ ...item, id: '123' })) Imagine that the testType interface is source ...

Even though I have successfully stored a key value pair in LocalStorage using JSON stringify and setItem, the data does not persist after the page is refreshed

I recently developed a Todo application that runs smoothly, except for one crucial issue - the localStorage data does not persist after refreshing the page. Initially, the localStorage operations functioned properly when there were fewer event handlers in ...

I'm not sure where to place this line of code in the updated Meteor file structure

I am a newcomer to the Meteor JavaScript library and although I have a grasp of its conceptual framework, I am seeking real-world experience with it. However, I have noticed a discrepancy between the tutorials provided by Meteor.com and the actual code tha ...

Saving the retrieved data from a JQuery $.post request into a JavaScript global variable

Currently utilizing Javascript and JQuery. A declaration of a Variable var RoleID=""; is stationed outside all functions. There exists a function: role_submit(){ var role=$('#emp_role').val(); var url="submitrole.php"; $.post(url, {role2: rol ...

I'm curious if there is a method to incorporate an array within a where: $or statement using sequelize?

I have an array of team IDs called teamsIdsSelected = ['1', '5', .., 'X'] In order to retrieve all the challenges associated with each team ID from the 'Challenge' table, I attempted the following: Utilizing this f ...

SignalR gets stuck on the 'Initiating start request' screen, halting all progress

SignalR has been causing some strange behavior for me lately. After doing some refactoring, I started experiencing connectivity issues. It seems like my code was just lucky to work before because it didn't follow the recommended practices. For example ...

Reloading the ASP.NET MVC bootstrap modal using Ajax for a fresh look

I'm struggling with my bootstrap modal. Whenever I click the submit button, the page refreshes and the modal disappears. How can I keep the modal open after clicking the submit button to display either a success or error message? I am new to MVC and h ...

Fixing Typescript assignment error: "Error parsing module"

Trying to assign an object to the variable initialState, where the type of selectedActivity is Activity | undefined. After using the Nullish Coalescing operator (??), the type of emptyActivity becomes Activity. However, upon execution of this line, an err ...

Display and conceal the information with a hyperlink

I need to create a content DIV that includes a link to expand and collapse it. Within this content DIV, there is an unordered list. Initially, only two list items should be displayed with an expand link. If users want to see additional list items, they mu ...