title: Passing Javascript Variable to PHP using Ajax
body: <p>I'm working on an existing script at the moment which uses Ajax, something I've never worked with before. I have a variable set in my javascript file which gets its value from an input field on my page. I need to use Ajax to post this to my PHP page only I've no idea where to start, </p>
  
  <p>Im not sure what code you would need to see, but My javascript/AJAX code is, the variable I need to pass is 'var credoff'</p>
  
  <pre><code>$(".getPoint").click(function () {
      var theid = $(this).attr("id");
      var onlyID = theid.split("_");
      var onlyID = onlyID[1];
      var credoff = parseInt($(this).children('input.credoff:hidden').val());
  
      $.ajax({
          url: 'do.php',
          type: 'POST',
          data: "userID=" + onlyID,
          success: function (data) {
              if (data != "success1" &amp;&amp; data != "success5") {
                  $("#" + theid).text(data);
              } else {
  
                  $("#thediv_" + onlyID).fadeOut("slow");
                  $('#creditsBalance').fadeOut("slow");
                  newbalance = parseInt($('#creditsBalance').text());
  </code></pre>
  
  <p>Wouldit have to be in this format?</p>
  
  <pre><code>data: "userID=" + onlyID,
  "credoff=" + credoff
  </code></pre>