JavaScript is based on Ajax editing information usage examples _javascript tips

Source: Internet
Author: User

The examples in this article describe the way JavaScript edits information based on Ajax. Share to everyone for your reference. as follows:

Requires prototype.js function edit (action, obj) {element.hide (obj); var textarea = ' <div id= ' + obj.id + ' _editor ' ><input type= ' text ' id= ' + obj.id + ' _edit ' name= ' + obj.id + ' '
  Value= "' + obj.innerhtml + '" "size=" > "; var button = ' <input id= ' + obj.id + ' _save ' type= ' button ' value= ' save '/> <input ' id= ' + obj.id + ' _cancel ' Typ
  E= "button" value= "Cancel"/></div> ";
  New Insertion.after (obj, Textarea+button);
  Event.observe (obj.id+ ' _save ', ' click ', Function () {saveChanges (action, obj)}, False);
  Event.observe (obj.id+ ' _cancel ', ' click ', Function () {cleanUp (obj)}, False);
  $ (obj.id+ "_edit"). focus ();
$ (obj.id+ "_edit"). Select ();
  function cleanUp (obj, keepeditable) {element.remove (obj.id+ ' _editor ');
  Element.show (obj);
if (!keepeditable) showaseditable (obj, true);
  function saveChanges (action, obj) {var new_content = Escape ($F (obj.id+ ' _edit '));
  obj.innerhtml = "Saving ...";
  CleanUp (obj, true); var success = function (t) {EDITCOmplete (t, obj);}
  var failure = function (t) {editfailed (t, obj);}
  var url = ' poll-ajax.php?a= ' +action;
  var pars = ' id= ' + obj.id + ' &content= ' + new_content;
var myajax = new Ajax.request (URL, {method: ' Post ', Postbody:pars, Onsuccess:success, onfailure:failure});
  function Editcomplete (t, obj) {obj.innerhtml = T.responsetext;
Showaseditable (obj, true);
  function editfailed (t, obj) {obj.innerhtml = ' Sorry, the update failed. '
CleanUp (obj);

 }

The

wants this article to help you with your JavaScript programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.