Return and print value passed through php script from javascript object using jquery ajax -


i have following code: javascript object:

 var getdbresults = (function () {       function getresult(url,tablename ,callback){         $.ajax({             url: url,             type: 'post',             data: {                 'table':tablename,             },             datatype: 'json',             success: function(data){                 callback(data);                 console.log(data)              },             error: function(){}         });     }        return {         getallvideoes: function(){             getresult("getallresults.php", "videoer", function(data){                 return data;             });         }     }  })(); 

simple php script:

<?php      $tablename = $_request['table'];      echo $tablename; ?> 

my js command fetching(seperate script ofc):

    var obj = getdbresults;     var data = obj.getallvideoes(); console.log(data) 

my issue callback function. wont output , doesn't seem running @ all.. had issue quite som time , cant figure out.. there i'v been missing? apriciated! sorry spelling btw.

you ajax expecting

`datatype: 'json',` 

json output php script

you returning html/plaintext data

`echo $tablename;` 

try json_encode

echo json_encode(array($tablename));  

result not in json format, when jquery fails parse it,

you can catch error ajax's error: callback function


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -