Link to home
Start Free TrialLog in
Avatar of peter-cooper
peter-cooper

asked on

Ajax success not firing alert

Hello
I seem to be having trouble processing any data from success event. I notice that this only happens if there is an 'echo' in the php backend. If I remove the 'echo' the success displays an alert but obviously no values. I can see the value in firebug but not in 'success(data)';

I cannot see why this is happening and would appreciate some help in solving this. I have posted the relevant code, but if You need more, then I shall be happy to post. I am using jqwidgets grid and for most part, works flawlessly. Thanks

index.php

// update the action row when the user clicks the 'action' button.
$("#Action").click(function() {
   var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', acteditrow);
   if(acteditrow >= 0) {
      var row = {
         rack: $("#rack").val(),
         row: $("#row").val(),
         column: $("#column").val(),
         bay: $("#bay").val(),
         size: $("#size").val(),
         activity: dataRecord.activity,
         service: dataRecord.service,
         department: dataRecord.department,
         company: dataRecord.company,
         address: dataRecord.address,
         item: dataRecord.item,
         user: dataRecord.user,
         destdate: dataRecord.destdate,
         date: dataRecord.date
      };
      var rowid = $('#jqxgrid').jqxGrid('getrowid', acteditrow);
      $('#jqxgrid').jqxGrid('updaterow', row);
      $("#actionWindow").jqxWindow('hide');
   }
   var data = "action=action" + "&rack=" + row.rack + "&row=" + row.row + "&column=" + row.column + "&bay=" + row.bay + "&size=" + row.size + "&activity=" + row.activity + "&service=" + row.service + "&department=" + row.department + "&company=" + row.company + "&address=" + row.address + "&item=" + row.item + "&user=" + row.user + "&destdate=" + row.destdate + "&date=" + row.date + "&id=" + rowid;
   $.ajax({
      cache: false,
      dataType: 'json',
      url: 'data.php',
      data: data,
      success: function(data) {
         
         alert(data);
      }
   });
   //$('#jqxGrid').jqxGrid('refresh');
});

Open in new window


data.php (test file)

if(isset($_GET['action']))
{
   if($activity == 'New Intake') {
      $rows[] = array("result" => 'This is JSON data');
      $json = json_encode($rows);
      echo $json;
   }
}

Open in new window

Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Set in ajax type:'post' then data:{data:trigger} and in the php if isset $_POST['data']
Or alternative data:{data:data}
Avatar of peter-cooper
peter-cooper

ASKER

@Leonidas sorry I am confused. Could you mark up the relevant section of my code. Thanks
ASKER CERTIFIED SOLUTION
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much
You welcome.In the data key value pair you can set instead of all this string action etc... the string trigger for more a quick way