how to sync the function with ajax struct in it to eliminate undefined

Viewed 17

i get all the time undefined if i use the code in that way. how can i solve that? btw. jquery 3+ seams that they doesnt support async = false. in that example i clicked on an imaginary fx_000_menus button with ix=0,jx=1 to starts the process. thx for any help

// stuff function to create buttons above
//..
function fx_000_ajaxRequest( arrIn ){
  var arr = arrIn.split('|');
  var errorMSGs = $('#000_err');
  var dataX = {};
  for( var i=0;i<arr.length;i++ ){ dataX['var'+(i)] = arr[i] }
  $.ajax({
    url: 'all.php', method: 'POST', data: dataX, async: true, dataType: 'json', contentType: "application/json; charset=utf-8",
    success: function(data){
      var a_output = data.split(' ++++ ');
      if( a_output[0] == 'OK' ){
        if( dataX['var0'] == '0' ){ return a_output[1] }
      }else{ errorMSGs.html(a_output[0]); }
    }
  })
}

function fx_000_readWriteDataFile( nr, str ){
  if( nr == 0 ){
    return fx_000_ajaxRequest( str ) // undefined
  }
 }

function fx_000_menus( wo, ix, jx ){
  var x = document.getElementById( wo )
  var html = ''
  if( ix == 0 && jx == 0 ){ html = fx_000_neueEintrage( wo ) }
  if( ix == 0 && jx == 1 ){ html = fx_000_liste( wo ) }
  x.innerHTML = html
  aufklappMenu( wo, '1' );
 }

function fx_000_liste( wo ){
  var id = 0
  var file = 'dateien/'+id+".txt"
  var html = fx_000_readWriteDataFile( 0, '0|fopenStream|'+file ) // undefined
  //var html = fx_000_ajaxRequest( '0|fopenStream|'+file ) // also undefined
  return html
 }
0 Answers
Related