I've followed just about every guide and tutorial that I can lay my hands on but I just can't see what's causing this problem:
I use the following code:
function updaterow(){
$.ajax({
url: 'updaterowajax.php',
type:'POST',
data: 'ID=' + ID + '&SupStatus=' + SupStatus +'&$OrderOther=' + OrderOther,
success: function(result){
console.log(result);
}
});
}
To post the contents of a form to a php-page. But for some reason it doesn't seem to send this as a post. And it especially doesn't send it to the correct page.
What I end up with is this in the address bar:
orderlist.php?ID=36&SupStatus=2&OrderOther=Ska+binda+Telia+Liten+18+m%E5n.&Submit36=Spara
That's the name of the file where my AJAX-script is in. What it seems to be doing (to me) is that it's sending a GET to the current page instead of a POST to the "updaterowajax.php".
Am I doing something wrong here? All the info in the GET is correct but it's not passed on.
Anything wrong in the code or perhaps the setup of my server? Default Apache, MySQL and I've got jQuery 1.7.1
The Form that's supposed to be posted:
while ($row = mysql_fetch_array($query)) {
echo "<tr><form id='".$row['ID']."'>
<td class='idcell'><input type='text' name='ID' readonly='readonly' value='".$row['ID']."' /></td>
<td>".$row['ArtName']."</td>
<td>".$row['ArtNumber']."</td>
<td><a href='/singlepost.php?ID=".$row['ID']."' title='Skriv ut ".$row['CustName']."'>".$row['CustName']."</a></td>
<td>".$row['CustContact']."</td>
<td>
<select name='SupStatus'>
<option value='".$row['SupStatus']."'>".$row['SupRealStatus']."</option>
<option value='01'>Mottagen</option>
<option value='02'>Lagd i korg</option>
<option value='03'>Beställd</option>
<option value='04'>Ankommen</option>
<option value='05'>Slutförd</option>
<option value='06'>Nekad</option>
</select>
<td>".$row['SupRealName']."</td>
<td>".$row['Date']."</td>
<td><textarea name='OrderOther' cols='40' rows='3'>".$row['OrderOther']."</textarea><input type='submit' value='Spara' name='Submit".$row['ID']."' onClick='updaterow()' /></td></form></tr>";}
And the updaterowajax.php
<?php
$ID = $_POST['ID'];
$OrderOther = $_POST['OrderOther'];
$SupStatus = $_POST['SupStatus'];
mysql_connect ("localhost", "root", "bilradio388") or die ('Kan inte ansluta till databasen för att: ' . mysql_error());
mysql_select_db ("bil_best");
mysql_query("UPDATE BestTable SET OrderOther = '$OrderOther' WHERE ID = '$ID'");
mysql_query("UPDATE BestTable SET SupStatus = '$SupStatus' WHERE ID = '$ID'");
echo "Dra på trissor"
?>
Think that's it!
EDIT: As I mentioned in my post further down I managed to get it working for a while. I used the suggested method: onClick='return updaterow();' and it was actually working. For three tries. Then I changed some code and it stopped working. I have reverted back to the old working state but alas, no, it doesn't work anymore :P I was thinking that I had missed out on a ' or " or ; or whatever, but so far I haven't found the missing link. I will report back if I find it. However, the above stated method seems to work.
EDIT 2: Well, got the "prevent form to be sent normally" to work (not that hard thanks to you) but firebug tells me that the ID is not defined. I find this weird since I haven't changed anything from when it did work to input into the database. But just to be clear: Am I missing something? The code above should actually define the value of ID, right? Especially since it seems that the code has no problem defining it when it's sent as a GET.