Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post

    Ajax Function Missing I think, please help

    Hi,

    I am trying to work out how to do an external ajax page.

    What I am doing is I have a selection of buttons and if they are clicked I want to call my external ajax page which will then call the information.

    So on my webpage I have the below:

    Code:
    <head>
    <script type="text/javascript" src="myajax.js"></script>
    </head>
    <body>
    <input type="button" name="MyCar" value="My Car"  onclick="ShowMyCars()" />
    <input type="button" name="XCar" value="X Car"  onclick="ShowXCars()" />
    <input type="button" name="YCar" value="Y Car"  onclick="ShowYCars()" />
    <br />
    <br />
    <div id="txtHintMyCar"></div>
    </body>
    So as far as I can tell I may be missing a function to call my AJAX page.

    The myajax.js code is
    Code:
    var xmlhttp
    
    function showMyCars()
    	{
    	if (str. length==0)
    		{
    		document.getElementById("txtHintMyCar").innerHTML="";
    		return;
    		}
    	xmlhttp=GetXmlHttpObject();
    	if (xmlhttp==null)
    		{
    		alert ("Your browser does not support XMLHTTP!");
    		return;
    		}
    	var url="getMyCars.php";
    	url=url+"?q="+str;
    	url=url+"&sid="+Math.random();
    	xmlhttp.onreadystatechange=stateChanged;
    	xmlhttp.open("POST",url,true);
    	xmlhttp.send(null);
    	}
    
    function stateChanged()
    	{
    	if (xmlhttp.readyState==4)
    		{
    		document.getElementById("txtHintMyCar").innerHTML= xmlhttp.responseText;
    		}
    	}
    
    function Get XmlHttpObject()
    	{
    	if (window.XMLHTTPRequest)
    		{
    		return new XMLHttpRequest();
    		}
    	if (window.ActiveObject)
    		{
    		return new ActiveXObject("Microsoft.XMLHTTP");
    		}
    	return null;
    	}
    I guess the problems I have at this stage are:
    1. Do I need a call function to my ajax page and if so what?
    2. Do I have the correct scripts on the right pages?
    3. Is there anything else I am doing wrong which I should be aware?

    Needless to say nothing is happening at the moment.

    Any assistance would be great.

    Jenny

  • #2
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post
    I forget to add that I have extra cols in the table which get filled in later

  • #3
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    360
    Thanks
    9
    Thanked 53 Times in 52 Posts
    Seems that you are trying to use ajax, with 'GET' method instead of 'POST'.
    This ref might help: http://www.w3schools.com/ajax/ajax_x...tatechange.asp

    See which method your getMyCars.php uses to read params.

    Hendra

  • #4
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post
    Thank you. Important information.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •