Using Javascript calls with the Ajax WebMethod technique

I've been facing issues running a JavaScript program on my online server. I'm considering another approach:

Using Ajax WebMethod with JavaScript calls:

<script type="text/javascript">
    function gettime(){
        var hour = new Date().getHours();
        document.getElementById("hr")=hour;
    }
</script>

ASP.net 4.0:

<WebMethod(EnableSession:=True)> _
    Public Function HourFromJavascript() As Integer
        printhour='hr from gettime
    End Function

Answer №1

No AJAX requests are being made to your server-side web method. A simple solution would be to utilize jQuery's AJAX functionality. Moreover, it seems like you're attempting to send data from the client to the server, but a more detailed explanation of your goal is necessary.

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

Using a combination of jQuery and JavaScript to switch image tags between different classes

I'm really struggling with this issue and could use some guidance. Essentially, I have a code that should change the class of an img tag when a user clicks on a div element. Let's take a look at the HTML structure: <li><img src ...

Issue with Laravel 5.7 Autocomplete search: JavaScript unable to recognize the specified route

I've been following a tutorial on this video: https://www.youtube.com/watch?v=D4ny-CboZC0 After completing all the steps, I encountered an error in the console during testing: jquery.min.js:2 POST http://apr2.test/admin/posts/%7B%7B%20('autocom ...

Tips on extracting information from an AJAX call using JQuery

My current project involves utilizing a webapi in asp.net that outputs JSON data. I am looking to integrate this webapi with JQuery within a php-created website. The following is the JQuery code I am using to retrieve information from the webapi: $.ajax( ...

How to display a three.js scene in the center of a container

I'm having trouble getting my three.js scene to display above some cards and right below my navigation bar. Currently, the scene is rendering under the cards and is not centered. Despite looking at other forum posts for help, I can't seem to figu ...

Generate a dynamic file import loop within a React application

Suppose I have a directory containing several .md files: /static/blog/ example_title.md another_example.md three_examples.md and an array that includes all the titles: const blogEntries = ["example_title", "another_example", "three_examples"] In ...

Only dispatch to props upon being clicked

I am encountering an issue with the mapDispatchToProps function being sent as a whole, rather than only when I click on the delete button. My class successfully fetches the list data and everything works as expected. However, upon adding the delete button ...

Dealing with duplicate entries on MySQL using AJAX

After successfully entering data into a database and displaying it on a table, I wanted to incorporate a message for possible duplicates. However, when the PHP script returns a "duplicate found" message, it disrupts the flow of the table scheme. My AJAX c ...

All outcomes being displayed from Youtube's json feed

Currently, I am retrieving a youtube playlist by using the following link: I'm curious if there is a method to display all 250 videos from my feed instead of just the 25 that are currently being shown. Any assistance on this matter would be highly a ...

Do elements containing {visibility:hidden} properties exist within the HTML DOM structure?

Do HTML elements that have the css property visibility:hidden still exist within the DOM tree? ...

Executing a Python script in Django and transferring its output to a JavaScript file

Getting Started with Django What I'm Looking For: 1 - Execute a Python Script 2 - Pass data to a JavaScript file I'm unsure if the sentence I've constructed is technically accurate in terms of Django. Below are the JavaScript and Python ...

Angular: The elusive "tab" key event fails to trigger

I am facing an issue with a form field and its handler function. I need the handler to be triggered only when the user deliberately accepts the value using either the return/enter key or tabs to the next field. Using the onBlur event is not an option in th ...

The AngularJS framework is failing to disable the autocomplete feature for the input field with a password type

I have attempted to disable auto-complete for the password input, but it doesn't seem to be working. Below is a sample of my code: <form name="testfrm" ng-submit="test(testfrm)" autocomplete="off"> <input type="password" id="passwor ...

Inserting HTML content into a DIV with the help of jQuery

Looking for a solution with my index.html file. I want to load other HTML files into a DIV by clicking on buttons. Here's an example of what I'm trying to achieve: I've searched through various examples online, but none seem to work for ...

Can I safely keep a JWT in localStorage while using ReactJS?

As I work on developing a single page application with ReactJS, one question comes to mind. I came across information indicating that using localStorage may pose security risks due to XSS vulnerabilities. However, given that React escapes all user input, ...

Getting a value from an event listener in Node.js: Can it be done?

How can I retrieve a value from an event listener? Check out the example below: const EventEmitter = require("events").EventEmitter; emitter = new EventEmitter(); emitter.on("sayHello", function(message) { return message + " World"; }); let helloMe ...

What is the method in JavaScript to display the information stored in a title attribute?

Can anyone help me with this code snippet I have? <i class="my-class" title="AB"> ::before </i> I need to extract and output the value of the title attribute, which is AB Example output should be: <span class="my-class">AB</spa ...

Error: The 'export' key was not expected. (JavaScript code: 33)

The browser error message lacks detail, and my attempts to find a solution have been unsuccessful. An error only occurs when I include this line at the top of my ToDo component: import Checkbox from '@material-ui/core/Checkbox'; It is important ...

Learn how to trigger a Bootstrap 4 modal simply by clicking a button on the initial page, which will then direct you to a second page where the modal is already activated

In my current project, I am working with Bootstrap 4 and I have a specific requirement to implement a modal. The modal should function in the following way: Upon clicking a button on the first .html page, I want to be redirected to a second .html page wh ...

Encountered an issue with loading the source: received an error for an unsupported URL while attempting

I am attempting to implement a basic post request on a route using a mongo DB in my JavaScript file. Here is the code snippet: var express = require('express'); var app = express(); var router = express.Router(); app.use(express.static('pub ...

The parameters for Vue.js @change events are consistently returning as 0 whenever a file is uploaded by clicking on the picture

Check out my JSFiddle here:: https://jsfiddle.net/includephone/o9gpb1q8 I've encountered an issue involving the @change event on an input field. My goal is to create a carousel of images with 4 images per slide. Data Object Structure data: functio ...