开发者

Don't know what $.post is returning

开发者 https://www.devze.com 2023-04-12 20:54 出处:网络
EDIT: I\'m getting the object {\"readyState\":1}. Why is that? How can I return the result from the $.post (i.e. the object {\"result\":\"ERROR\"}开发者_开发知识库).

EDIT:

I'm getting the object {"readyState":1}. Why is that? How can I return the result from the $.post (i.e. the object {"result":"ERROR"}开发者_开发知识库).


Using jEditable. (Note: I think this is a simple jQuery question as opposed to a specific plugin question.)

I would like to see if a unique tag symbol already exists in the database. As such, I do a $.post on onsubmit and get a JSON object returned {"result":"ERROR"} (I know this using firebug).

My problem is I'm having trouble handling the data returned. When I do alert(returned) I just get a Object object response and not "TEST".

Any tips on what's wrong or how to find out what's going wrong?

CODE

//Edit Tag Symbol
$(".edittagsymbol").editable('myURL',{
    onsubmit : function(settings, td){
        var id =  $(this).attr('id');
        var input = $(td).find('input');
        var original = input.val();
        var returned = $.post('myURL',{"text": original}, 
                                function(data) {
                                    if (data.result == 'ERROR'){
                                        return data.result;
                                    }
                                },
                                "json"
                            );
        alert(returned);
    }
});


$.post does not return the value returned from the passed function. It returns a jqXHR object instead.

If you want to do something with your data, you should use a callback function.

A useful example is in the accepted answer here.


use alert(JSON.stringify(returned)) to see what is the error. Because you expect JSON from server

0

精彩评论

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

关注公众号