Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

how to get out of jquery (jeditable) mess

I am not very good at jQuery but decided to use jEditable plugin for my site because I thought it looked good and solved the purpose. However, I am in a bit of a tangle now.

I used this plugin to edit data and the edited data is sent to the DB and some fields are updated by it. the Stored procedure that updates these fields is returning some data back. I would like to have this data returned back to me. I would just like to see the returned data in an 'alert' statement first, then I can take it from there.

The callback method of this plugin just has value, and settings.

Is there any way to get some data back from the server-side while using this plugin?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have done exactly this for my site. This should get you started.

$("#editable_text").editable(submitEdit, { 
            indicator : "Saving...",
            tooltip   : "Click to edit...",
            name : "Editable.FieldName",
            id   : "elementid",
            type : "text",
});
function submitEdit(value, settings)
{ 
   var edits = new Object();
   var origvalue = this.revert;
   var textbox = this;
   var result = value;
   edits[settings.name] = [value];
   var returned = $.ajax({
           url: "http://URLTOPOSTTO", 
           type: "POST",
           data : edits,
           dataType : "json",
           complete : function (xhr, textStatus) 
           {
               var response =  $.secureEvalJSON(xhr.responseText);
               if (response.Message != "") 
               {
                   alert(Message);
               } 
           }
           });
   return(result);
 }

You need to return a Json response of the form

{ "Message" = "FOO" }

And that will be displayed in the alert.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...