Jump to content

onClick via A HREF


MikeDXUNL

Recommended Posts

When a user click "Owned" it should move it to their owned List.... thats not the case though...

actions.js

var xmlHttp

function newadd(str2, str3, str4)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ajax/whattodo.php";
url=url+"?gameid="+str2"&whereto="+str3"&type_q="+str4;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}



function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("txtHint7").innerHTML=xmlHttp.responseText;
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

 

 

myfile.php

<div id="txtHint7"></div>
<a href="#" onClick="newadd('<?php echo $gameid; ?>', 'Owned', 'videogames')">Owned</a>

 

whattodo.php

$gameid = (!isset($_GET['gameid']) || !is_numeric($_GET['gameid'])) ? "0" : $_GET['gameid'];



echo $gameid."<br />";
echo $_GET['whereto']."<br />";
echo $_GET['type_q']."<br />";

 

 

however nothing happens, any help is appreciated :)

btw, I am new to JS and AJAX :P

 

Thanks,

Mike

Link to comment
https://forums.phpfreaks.com/topic/86986-onclick-via-a-href/
Share on other sites

Doesn't look like there is anything wrong with your code.  Watch out for paths, make sure that var url="ajax/whattodo.php"; is the correct path to the whattodo.php file. 

 

The best thing for debugging Ajax is to download Firefox, if you don't already have it and download the Firebug plugin.  This shows you the calls and what is updated on the page.   

 

Link to comment
https://forums.phpfreaks.com/topic/86986-onclick-via-a-href/#findComment-446986
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.