Implementing different behaviors depending on the data with the updater of prototype.js

Asked 1 years ago, Updated 1 years ago, 85 views

Web site implementation with node.js + express.

I'm currently implementing the Like function.

While trying to find out by touching the ajax to make the page work without reloading,

I found a very good framework called prototype.js.

Currently, we have implemented receiving the result value in this prototype.js.

By the way, Request can be made to do different actions with an if statement depending on the result value,

The updater is impossible because it receives the result value and applies it to the element right away.

(I don't know how to use it because there is a grammar error even though there is an evalScipps option. )

new Ajax.Updater({success:'like-action'}, "/like", {
              method:'post',
              parameters : {"no" : "1"},

              onLoading: function() {
              },
              onSuccess  : function(returnValue) {

              },
              onFailure  : function() {

              },
              onComplete : function(returnValue) {

              }
          });

The above code inserts the result value received from the server into the element id="like-action" upon successful processing.

I want to turn over the data handed over from the server to success: true, success: false, and increase the like value by 1 if it succeeds according to boolean, and if it fails, I want to display an alert window.

ps. I know how to get a value in Request, but $("#")Jquery grammar like after() didn't work.

prototype ajax jquery asynchronous

2022-09-22 08:28

1 Answers

Ajax.The official document for the Request [1] indicates that onSuccess can handle the response.

new Ajax.Request('/your/url', {
  onSuccess: function(response) {
    // // Handle the response content...
  }
});

Ajax was the first factor in OnSuccess.It is stated that it will be delivered to Response[2][3].

If you receive JSON data and the Content-Type response header is application/json, you can use the responseJSON property.[4] If not, I think you can use the responseText attribute.[5]


2022-09-22 08:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.