php - AJAX no data showing up from server request -


i tryng ajax post seperate php file , have data put div. ultimate goal set long poll auto updating, baby steps.

so nothing shows in div when page loaded. checked console , ajax send 'initiate' post doesn't seem receive except headers.

fixed whole time missing curly brackets. syntax guys.

here code

php file ajax calls

<?php require "dbc.php";      $function = $_post['function'];        switch($function)     case('initiate'):     $search="select * feedtest order id desc";     $request = mysql_query($search);     $mostrecent= mysql_fetch_array($request);     $mostrecentid = $mostrecent['id'];     header("content-type: application/json");     echo json_encode($mostrecentid);      break;        case('update'):     $search="select * feedtest order id desc";     $request = mysql_query($search);     $update= mysql_fetch_array($request);     $updateid = $update['id'];     header("content-type: application/json");     echo json_encode($updateid);      break;           ?> 

the page call made

<div id="datacheck"></div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>    <script>   $(document).ready(function()  {      $.ajax({           type: 'post',           url: 'feedupdate.php',           data: {function: 'initiate'},           datatype: "json",           success: function(msg) {               $('#datacheck').html(msg);           }          });   }); // document ready  </script> 

you forgot , here

data: {function: 'initiate'}, // here datatype: "json", 

also

'function': 'initiate' 

should be

function: 'initiate' 

function reserved word in javascript, need change other name well.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -