Jquery- Modify Element Value after ajax call -
enter
Scenario: I make an AJAX call to update Image shown shown Picture: Click to activate, click again to deactivate.
Now, for the first time, the image can change correctly.
After that, if I click IMG again,
reason, onclic status still = yes how do I onclick "onclick =" update ('7', ' No ') in the context to use the hyperlink element to rewrite
& lt; A href = "#" onclick = "update ('7', 'yes')" & gt; & Lt; Img id = img7 border = 0 src = "img / active.gif" & gt; Function Update (PK, Enabled) {$. Type {ajaxcall.asp}, type: "POST", success: function (output) {var status = output if (status = = 1) {var src = ($ ('#' + 'img' + Pk) .attr ("src") == "img / cross.gif")? "Img / tick.gif": "IMG / cross .gif"; $ ('#' + 'img' + pk) Attr ("src", src); // REFER HERE}} complete: function () {}, data: 'pk =' + pk + '& amp; amp; enabled =' + enable}}}}
here
I want to do it this way. First of all:
& lt; An id = "a7" href = "#" & gt; & Lt; Img border = "0" src = "img / active.gif" & gt; & Lt; / A & gt;
then
$ (function () {$ ("# a7"). Update ("7");}); Function Update (PK) {var img = $ ("# img" + pk); If (img.attr ("src") == "img / cross.gif") {enabled = "no"; Var src = "img / cross.gif"; } Else {enable = "yes"; Var src = "img / tick.gif"; } $ .ajax ({url: "ajaxcall.asp", type: "POST", success: function (output) {var status = output; if (condition == 1) {img.attr ("src", src) ;}}, Complete: function () {}, data: 'pk =' + pk + '& amp; enable =' + enable}); }
You do not have to pass in yes or no you can get it from the image source.
Comments
Post a Comment