0

im fairly new to ajax.. but I have this function which takes and order id and query sql from it in a php page. I can set the returned data to a div but what id like to do is set the return from the function to the returned data in html or text form so i can email it later. also any better ways to do this code would be greatly appreciated

<script>
function getInvoice(id){
var request = "driverInvoice.php"+"?oID="+id;

  $.ajax({
    url: request,
    success: function(data){
    $("#theDiv").html(data);
    }
  });

}
</script>
zach f
  • 3
  • 4

2 Answers2

0

Use data: {oID: id} to send with POST.

function getInvoice(id){
$.ajax({
          async: false,
          type: "POST", //Method POST, you can edit and use GET
          url: 'driverInvoice.php', //URL
        data: {oID:id}, //Variables
          success: function(data){
              $('#theDiv').html(data);
          },
          error: function(data) {
          }
      });

}

Enzo Zapata
  • 171
  • 1
  • 7
  • hey thanks man but how would i change the $('#theDiv').html(data); to return data; without getting a undefined when i document.GetElementById('theDiv').innerHtml = getInvoice(9); later? – zach f Nov 27 '14 at 23:09
  • check it out http://stackoverflow.com/questions/5316697/jquery-return-data-after-ajax-call-success – Enzo Zapata Nov 27 '14 at 23:15
  • nice! dont forget to rate my answer :D – Enzo Zapata Nov 28 '14 at 00:35
0

If I undestend, you want transform data in text, like a strip_tags php function?

...
success: function(data){
   $("#theDiv").html(data);
   var text = $("#theDiv").text() 
}