Redox
Redox

Reputation: 993

$.post function, return is empty

I have a problem wit a $.post request. No errors, but the return is empty. Before I start bugging the server admin, of who the service is, with this problem. I want to make sure I did not make any mistake myself.

Below the code I'm using:

var post_data = JSON.stringify({'str_action':'log_element', 'int_id':'TEST', 'str_value':'EMPTY'});
$.post('http://url/', post_data, debug_return_data);

function debug_return_data(data)
{
    alert(data);
}

Problem is that the returned data in the alert is empty. Did I make any mistake in my code?

Thanks in advance.

Upvotes: 0

Views: 336

Answers (2)

ZiTAL
ZiTAL

Reputation: 3581

$.post('http://url/', post_data, function(data)
{
    alert(data);
});

this is in the jquery documentation

Upvotes: -1

reach4thelasers
reach4thelasers

Reputation: 26909

The Ajax call looks correct, check the response in firebug or chrome dev tools to make sure the server is actually returning data.

If you are making the AJAX call to anther server other than the one in the address bar it will be blocked as a cross-domain call. Use JSONP if you want to do this:

http://devlog.info/2010/03/10/cross-domain-ajax/

Upvotes: 3

Related Questions