Question

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.

Was it helpful?

Solution

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/

OTHER TIPS

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

this is in the jquery documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top