Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey guys someone knows this problem?
I start an ajax request, but Firebug tells the request is aborted. If you now take a right-click and open the request in a new tab, the request works. So the code has no mistake. But why I don´t recive the answer on the mainpage?

JavaScript
var xmlHttp = false;

       if (window.XMLHttpRequest) {
           xmlHttp = new XMLHttpRequest();
       } else if (window.ActiveXObject) {
           try {
               xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
           } catch (e) {
               try {
                   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
               } catch (e) {}
           }
       }


PHP
<?php
header('Content-Type: text/html; charset=utf-8'); 
header('Cache-Control: must-revalidate, pre-check=0, no-store, no-cache, max-age=0, post-check=0'); // ist mal wieder wichtig wegen IE
$id = $_POST['id'];
echo $id;
?>


PHP
echo "<script>
	function loeschen ()
		{
		var loesche = document.getElementById(".$id.").id;
		xmlHttp.open(\"POST\",\"loesch.php\",true);
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send('id='+loesche);
		xmlHttp.onreadystatechange = Callback();
		}
	function Callback ()
		{
		switch (xmlHttp.readyState)
			{
			case 4:
				if (xmlHttp.status != 200)
					{
					alert('Fehler');
					}
				else
					{
					loesche.innerHTML = xmlHttp.responseText;
					}
				break;
			default:
				break;
			}
		}
</script>";

Here i have the id:
PHP
echo "<a style='text-decoration:none; color:white' href='/Inhalte/Kategorien/".$kaufen[6]."' id='$id'  önclick='loeschen ()'>".$kaufen[0]."</a><br />";
Posted
Updated 21-Jan-13 9:37am
v2
Comments
Sergey Alexandrovich Kryukov 21-Jan-13 15:31pm    
You present no evidence that "code has no mistake"... :-)
—SA
Chi Ller 21-Jan-13 15:33pm    
But if the code would have some mistakes, it wouldn´t work by open the request in a new tab, right?
Richard C Bishop 21-Jan-13 15:36pm    
Just because it compiles, does not mean the logic is correct.
Chi Ller 21-Jan-13 15:38pm    
so now you have the code. You can convince youself about mistakes
Sergey Alexandrovich Kryukov 21-Jan-13 15:56pm    
I cannot see why. This is a pretty usual behavior of wrong code: working in some cases, not in others.
Also, you fail to follow simple logic. What do you call "right" code? If it does not achieve what you wanted to achieve, it is already wrong, in this sense...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900