如何在功能deviceready内部发布到Ajax?

 收藏

I'm using a function to call deviceready which works well. I'm putting this outside $(document).ready however and I need to know how to post to ajax when it's not inside the ready() function. Right now, deviceready works but it's not posting to ajax. It posts fine if inside the $(document).ready.

device.js

function init() {
  document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {

  console.log('device ready');

  //post to ajax
  $.ajax({
    type: 'POST',
    url: 'geolocation.php',
    data: values,
    success: function (data) { }
  });

}
回复