I have no problem to change background when I click on anchor. The problem was that is does not turn back after some time. I also think about skipping the delay or fadeout and to try do it as follows: If I edit a element and click on Save, then it is displayed "Saved!" with green background. If I would focus the form element again, to edit it again, then the default class would be added and "" text will display. This sound pretty simple.
I tried to find some simpler solution using "this" and referring to next sibling. I use 27 anchors that can save up to 27 elements. Also 27 spans to display action status. So I think it would be good to find more relative way rather than absolute way using 2x27 id's.
Which part of the a tag are you trying to include in the call-back function? As the code is at the moment, your call-back function isn't supposed to do anything.
Do you see the curly braces after function(data) without anything in them? That's where I can tell your function isn't meant do anything. Besides, you might have some syntactical error there. I don't think .post() API can have more than 3 parameters, and you have more after your call back function.
One more thing, your lateral way of coding kills my eye to read all those in the parentheses. When you want to something to happen as a function, try to define a function in your script and call it where needed in any tag you want.
urlA string containing the URL to which the request is sent.
dataA map or string that is sent to the server with the request.
success(data, textStatus, jqXHR)A callback function that is executed if the request succeeds.
dataTypeThe type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
--------------
To the code of mine:
Yesterday I placed some code in the anonymous function. No I do know know why it is empty now, maybe I wanted to simplify the code or forgot to insert the code in. I tried something like onclick"that=this;.post(...,...,function (data,that){console.log(that)})"
Which part of the a tag are you trying to include in the call-back function? As the code is at the moment, your call-back function isn't supposed to do anything.
If I did not write it here, then something like this
Code:
$(that).next().text("Saved!");
should be in the call-back function, where "that" is the anchor object. I will add condition later to it.
I'm sorry, but I lost track of what you intend to do with the call-back function. Would you write the function in a cleaner way so I can see your point better?
I tried to do it with callback function. Nevertheless, a problem with that occurred:
error: $(that).delay is not a function
on line 27: [Break On This Error] $(that).delay(1500).queue(
Code:
<script type="text/javascript" >
var callBackFnc = function(result){
that = this;
return function(result)
{
if (result=="Data succesfuly updated.") <!-- this is reply from server to AJAX -->
{
$(that).next().text("Saved");<!-- that refers on anchor; this is OK, span set! -->
$(that).delay(1500).queue( <!-- error -->
function()
{ $(that).next().text("").removeClass("off");
$(that).dequeue();
}
);
}
}
}
</script>
<body>
<textarea id=id cols="1" rows="1" >Some text here</textarea>
<a class=save href='localhost' onclick='var myfnc = callBackFnc.call(this);$.post("ax.php?action=post&save=1", { tabName: "basic", rid: $("textarea#id").val(), col:"id", val:$(this).prev().val() }, function (result){ myfnc(result);}, "html");return false;'>Save!</a>
<span></span>
</body>
I also pasted the code on Jquery official site, where it is with colors (that helps much!): colored code here
The code above should change text in span to Saved! and then this text should disappear after 1.5 s. The Saved! text will appear only if "Data succesfuly updated." comes from server.
I don't really understand how .queue API works on jQuery, but according to the official page, it can have 1 or 2 parameters.
When it has a parameter only, the parameter SHOULD be queue name, not a call back function.
When it has 2 parameters, then the first one is the queue name and the second one is the call back function.
Your code has only one parameter, so that parameter is assumed to be the queue name by the jQuery. However you're passing a function as the sole parameter. I don't think that logic should work.
Bookmarks