• I’ve searched the forum, because I can’t believe this is the first time this has come up but I can’t seem to find an answer. I’m creating a page and I want to insert some AJAX code into it. My code is below. It’s a simple script that uses a dropdown to display specific HTML source inside this page depending upon the option selected.

    When I upload this code to WP, and look at the source in a browser, it changes the single quotes to &#8217 and ‘ In any event it does not work.

    My page is here: https://heronsglenfitness.com/blog/?page_id=3

    <script language="javascript">
     var XMLHttpRequestObject = false;
     if (window.XMLHttpRequest) {
     XMLHttpRequestObject = new XMLHttpRequest();
     } else if (window.ActiveXObject) {
     XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
     }
     function getData(dataSource, divID)
     {
     if(XMLHttpRequestObject) {
     var obj = document.getElementById(divID);
     XMLHttpRequestObject.open("GET", dataSource); 
    
     XMLHttpRequestObject.onreadystatechange = function()
     {
     if (XMLHttpRequestObject.readyState == 4 &&
     XMLHttpRequestObject.status == 200) {
    		obj.innerHTML=XMLHttpRequestObject.responseText;
    
     }
    	 if (XMLHttpRequestObject.readyState == 1)
    	 {
    	 	obj.innerHTML="generating scorecard...";
    	 }
     } 
    
     XMLHttpRequestObject.send(null);
     }
     }
    function getScorecard(sel)
    {
    	var team = sel.options[sel.selectedIndex].value;
    	if (team == 1) 	{ getData('aaa.htm', 	'targetDiv') }
    	if (team == 2) 	{ getData('bbb.htm', 	'targetDiv') }
    	if (team == 3) 	{ getData('ccc.htm', 	'targetDiv') }
    }
     </script>
    
    <form action="" method="post">
    <table align="center" border="0" cellpadding="8" width="680"><tbody><tr><td align="right"><b>Team:</b></td><td align="left"><select id="dhtmlgoodies_country" name="team" onchange="getScorecard(this)"><option value="" selected>Select a team</option>
    <option value="1">aaa</option>
    <option value="2">bbb</option>
    <option value="3">ccc</option>
    </select></td></tr><tr><td colspan="3" align="middle"><b>
    <div id="targetDiv"></div>
    </b><br /></td></tr></tbody></table>
    </form>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add some AJAX to my WP page’ is closed to new replies.