我已经多次看过这个问题而且我已经尝试过实施解决方案,但这对我不起作用。你如何在同一页面上正确地发布ajax请求并在php中检索数据?
<?php
error_reporting(-1);
var_dump($_REQUEST);
var_dump($_POST['img_url']); # ALWAYS NULL
?>
<script type='text/javascript' src='/steal/steal.js'></script>
<script type="text/javascript" src="/plugins/jquery/json2.js"></script>
<script type="text/javascript">
steal('jquery/dom/fixture').then(function(){
$.fixture("GET /event/{code}", function(original, settings, headers){
return [200, "success", { "img_url":"http://path/to/img.png" }, {} ]
})
var strObj = <?php echo json_encode($_REQUEST); ?>;
var str = strObj.q;
var eventCode = str.split('/')[1];
console.log(eventCode);
$.ajax({
url: "/event/"+eventCode,
success: function(data) {
//document.write('<img src="'+data.img_url+'"/>');
$.ajax({
type: 'POST',
data: {img_url : data.img_url}
});
}
});
});
</script>