0

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);
    }
});
Kamil Sindi
  • 21,782
  • 19
  • 96
  • 120

2 Answers2

3

$.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.

Community
  • 1
  • 1
Przemek
  • 6,300
  • 12
  • 44
  • 61
1

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

Sedat Başar
  • 3,740
  • 3
  • 25
  • 28