protocol = window.location.protocol host = window.location.host function get_question() { $.ajax({ url:protocol+"//"+host+"/api/get_question.php", data:{}, dataType:"json", type:"POST", success:function(data) { if (data.result == 'success') { $("#get_question").html('('+data.msg+')'); } else if (data.result == 'error') { $("#get_question").html('('+data.msg+')'); } } }) } get_question();