Implementing Table Updates in Yii2 using Ajax Calls

I've developed a JavaScript script and Controller Action to update a field when a button is clicked as shown below.

Although I receive a success response, the table does not get updated.

    public function actionSetstarttime()
    {
    
    if (Yii::$app->request->isAjax) {
        $data = Yii::$app->request->post();
        $mySaveId =  $data['save_id'];

        $timeRecord = teammembers::find()
            ->where(['=', 'id', $mySaveId]) 
            ->one();
        $timeRecord->time_start =  12345;
        //Yii::$app->formatter->asDatetime('now', 'php:Y-m-d H:i:s');

        $timeRecord->save(false);

        return $timeRecord->time_start;
    }
 } // }}} 

The JavaScript code in the view is:

$('._starttime').on('click', function(event){
    event.preventDefault();
    $.fn.timer.worker.go();
    var first = $("#timeslot_id").val();

    $.ajax({
            type: "POST",
            url: "/site/time",
            data: 'save_id='+first,
            success: function (data) {
               //do something
                console.log(data);
               alert("working");
            },
            error: function (exception) {
                console.log(exception);

            }
        });
    });

Answer №1

It seems like there might be an issue with the URL in SiteController.php file that you are using for your controller. If your action requires it, consider adjusting your URL to something like this:

$.ajax({
        type: "POST",
        url: "/site/setstarttime",
         .....

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

Create div elements using JSX and add them to an array

I am working with a structure that looks like this: var circle = { 'one': {items: []}, 'two': {items: []}, 'three': {items: []}, 'four': {items: []} }; Each items array needs to contain 10 unique ...

Display outcomes for chosen checkboxes

When I call the API: $url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order=' . $orderrecords[$k]["order_id"] . '&username=admin&password=admin123';, I retrieve the status results of all Order IDs and d ...

Adjust the primary scrolling section of a webpage to halt once it reaches a specific distance from the bottom of the viewport

I am facing a situation where I need to ensure that when scrolling down, a fixed pink menu bar at the bottom of the page does not overlap with the main blue content. This can be achieved by treating the blue content as an iframe positioned 60px from the bo ...

Can an older style class be inherited from an ECMAScript 6 class in JavaScript?

When I run the code below on Node.js version 4.2.1: 'use strict'; var util = require('util'); class MyClass { constructor(name) { this.name = name; } } function MyDerived() { MyClass.call(this, 'MyDerived'); } ...

Facing difficulty observing Content-Disposition header in create-react-app project

I am using a create-react-app that is being served by express. Express is acting as a proxy for the app and all the application logic resides in CRA. My issue lies in calling an API to download a file. The API sends back a "Content-Disposition" header wit ...

Issues with Angular JS page loading when utilizing session and local storage in Google Chrome

I'm currently learning about AngularJS and I stumbled upon this helpful tutorial http://embed.plnkr.co/dd8Nk9PDFotCQu4yrnDg/ for building a simple SPA page. Everything was working smoothly in Firefox and IE, except when it came to using Local and Sess ...

Having trouble understanding how to display an HTML file using Next.JS?

Currently, I am working on a project that involves utilizing Next.JS to develop a webpage. The main goal is to display a PDF file on the left side of the screen while integrating Chaindesk on the right side to create a chat bot capable of extracting inform ...

Unable to locate a React component module that has been published

After successfully publishing a React component to NPM, I encountered an issue when trying to use it in another project - I couldn't find the module! Module not found: Can't resolve 'react-subreddit-posts' in '/Users/kyle.calica/C ...

How to use Selenium's scrollIntoView() method in the Internet Explorer browser?

Is there a way to use the selenium scrollIntoView() method for Internet Explorer? ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", _webElement_ ); I tried this approach but it doesn't seem to work. After doing some ...

One query, many replies: Golang's ability to handle multiple

As I work on implementing a web server to handle large queries, one challenge arises with the response size. Instead of sending the entire response in one go, my idea is to break it into smaller pieces and send them individually. For example, if I have an ...

An error with jQuery occurred in the client's post response, resulting in a 400 POST HTTP/1.1 error

I am struggling to identify the issue with my code, especially since I'm not very familiar with jQuery. The goal is to create an HTML form for storing car data based on this template: https://i.sstatic.net/u40nG.gif The source code for the HTML form ...

Can you guide me on how to establish a cookie within a selenium webdriver javascript script?

I am trying to figure out how to set a cookie using a basic webdriver script: WDS.sampleResult.sampleStart(); //WDS.driver.manage().addCookie(new Cookie("connect.sid", "s%3AeexeZcd_-S23Uh30e3Dmd4X9PskWF08s6m5hDurDa5Jj66SupmmiqvKEjAg6HGigl0o0V%2B9R7m4", ...

What is the best way to loop through all the child elements of a scene in three

Using Three.js: I have a method called removeBysid(id) My goal is to access the unique sid of the third child's treeNode in my scene by traversing through all the children. When I run the following command in the console: scene.children[4].child ...

having difficulty accessing or modifying the prototype's properties

Encountering an error while attempting to retrieve the keys of an object and all prototype objects. The issue arises when trying to access keys of the prototype. Here is what works: Object.keys(object) Object.keys(Object.getOwnPropertyDescriptors(object. ...

Retrieve the child scope of ng-repeat beyond the ng-repeat iteration and establish a two-way data binding

With my ng-repeat, I am attempting to include ng-model inside each repeated li, followed by two-way data binding outside of the ng-repeat. You can see the example in this jsbin: http://jsbin.com/yutinifivi/edit?html,js,output I have searched extensively f ...

The React router Link does not update the route after an if statement is executed

I'm in need of some assistance regarding React.js. Despite my efforts to find a solution, nothing has worked for me so far. Here are some examples of what I've searched for: How to use Redirect in the new react-router-dom of Reactjs Redirectin ...

Scroll horizontally through the number field in Chrome

I have configured a number input field with the text aligned to the right. Scenario: While testing, I discovered that selecting the entire text or using the middle mouse button to scroll within the input field allows for a slight leftward scrolling of ab ...

What is the best way to trigger a Quasar dialog from an outside component?

Currently, I am working with Vue.js 2.x + Quasar 1.x using http-vue-loader (no build tools required). I have placed a q-dialog in a separate component named MyComponent. However, when I try to include it in a parent component like this: <my-component&g ...

Encountering an issue with re-rendering components in REACT when using the setState hook

Is there a way to efficiently change the inline style property of multiple items based on their position info stored in a useState hook? I want to update the CSS value of all items except for the one that was clicked on. I tried using setState to achieve t ...

Steps for creating a Div element as a hyperlink without affecting the images it contains

Apologies for bringing up more queries regarding the same situation, but here it goes: Although my text is top-notch and images are perfectly placed, I am looking to prevent the jquery slide method from running when the images are clicked (as those clicks ...