php - Jquery ajax POST response is null -
i have js script ajax request , posts data php script, script echo depending if works or not.
here js
$(document).ready(function(){ var post_data = []; $('.trade_window').load('signals.php?action=init'); setinterval(function(){ post_data = [ {market_number:1, name:$('.trade_window .market_name_1').text().trim()}, {market_number:2, name:$('.trade_window .market_name_2').text().trim()}]; $.ajax({ url: 'signals.php', type: 'post', contenttype: 'application/json; charset=utf-8', data:{markets:post_data}, datatype: "json", success: function(response){ console.log("response " + response); }, failure: function(result){ console.log("failed"); console.log(result); } }); }, 6000); });
here php:
if(isset($_post["json"])) { $json = json_decode($_post["json"]); if(!empty($json)) { echo "it worked!!!!"; } else echo "not posted"; }
so basically, thought response in `success: function(response)' method populated either "it worked!!!" or "not posted" depending on if statement in php. seem work because js script manages go success statement prints console:
response null
i need able return server in order update screen.
any ideas i'm doing wrong?
try:
if(isset($_post["markets"])) { $json = json_decode($_post["markets"]); if(!empty($json)) { echo "it worked!!!!"; } else echo "not posted"; }
Comments
Post a Comment