开发者

How to get variable out of .ajax callback?

I am using the editInPlace jquery plugin for editing:

$(".edit-synonyms").editInPlace(varSettings);

The settings for it are:

varSettings=
                    {
                        show_buttons: true,
                        error_sink: null,
                        context: "#error",
                        callback: function(idOfEditor, enteredText, originalHTMLContent, settingsParams, callbacks) 
                        {
                            varID=$(this).attr('id');
                            var data ='update_value=' + encodeURIComponent(enteredText) 
                            + '&element_id=' + $(this).attr("id")
                            + '&original_value=' + encodeURIComponent(originalHTMLContent);
                            $.ajax({
                                    url: "/inc/ajax-synonim.asp?action=edit",
                                    type: "POST",
                                    data: data,
                                    dataType: "html",
                                    complete: function(request){

                            },
                                    success: function(html, textStatus){
                                        if (html != "False") {
                                            $.get('/inc/ajax-synonim.asp?action=sinonimke&ID=' + IDSinonimka, function(data){
                                                var开发者_C百科Besede=data.split("|");
                                                $('.sinonimke-'+IDSinonimka).text(varBesede[1]);
                                                $('.beseda-'+IDSinonimka).text(varBesede[0]);                                           
                                            })
                                        } else {
                                            alert("Word exists in database!")

                                        }

                                    }

                            })  
                            alert(error);
                            var new_text = enteredText || originalHTMLContent;
                            return new_text;


                        }
                    }

My problem is that I get what is returned from server side on .ajax success as html variable. But this variable is not seen in the Settings (outside of the .ajax call). If it is not visible, I can not deternine if the postback was false or a good value and I can not respond properly.

  1. Is there a way to see the html variable in the callback outside of .ajax function?
  2. If not, is there a way I could return the html value from the .ajax function to the callback of the inline editor?
  3. If not, is the ponly way to do another ajax call in callback to check for word if it exists?


At the end of your ajax asp script add this:

print "var yourvariable = yourvalue;"

and use something like this for your ajax call:

$.post("/inc/ajax-synonim.asp?action=sinonimke&ID=' + IDSinonimka",{your attributes}, function(sScript) {
    try {
        eval(sScript);
       } catch(error) {
            alert(error.message+"\n"+sScript);
       }
    return false;
});

Your php ajax script will print "var yourvariable = yourvalue;" and jquery will try to execute that script. Tadaa, you've got yourself your ajax variable parsed to javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜