title: How can I use jQuery´s $.ajax() function to run php script?
body: <p>To make this understandable I made an sample code because my actual code is much bigger. </p>
  
  <p>Basically what I want to accomplish is to run my PHP script that edits an XML file using ajax. This is because I need to do this inside a javascript in my real project.</p>
  
  <p>This is what I have so far:</p>
  
  <p>the .php file containing the ajax function:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  function editXMLDoc()
  {
    $.ajax({
    url: "sensors.php",
    context: document.body
  }).done(function() {
    $( this ).addClass( "done" );
  });
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;button type="button" onclick="editXMLDoc()"&gt;Endre XML&lt;/button&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is the php script writing to xml:</p>
  
  <pre><code>&lt;?php
  include 'sensor.php';
  $b=new sensor();
  
  $arr=$b-&gt;load('sensor.xml');         
  
  for($i=0,$ms=count($arr);$i&lt;$ms;$i++)
  {
    if($arr[$i]['fields']['status']=='1')
    {
       $arr[$i]['fields']['status']='0';
    }else{
      $arr[$i]['fields']['status']='1';
    }
  }
  echo "Completed&lt;br/&gt;";
  //3. save array to xml
  $b-&gt;save('sensor.xml',$arr);
  ?&gt;
  </code></pre>
  
  <p>I know the script is working so I am pretty sure the prob is the connection between the ajax function and the php script.</p>
  
  <p>Can anyone help me out?</p>