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 3 of 3

Thread: Ajax problem

  1. #1
    Fot
    Fot is offline
    Regular Coder
    Join Date
    Mar 2011
    Posts
    111
    Thanks
    88
    Thanked 0 Times in 0 Posts

    Ajax problem

    Hello, first I have a code with ajax and cannot operate the onChange.ALso
    it cannot see the picture.
    Code:
    <select name="cs"  onChange="ajaxRequest(this)">
    <div id="result"> </div>



    Code:
    function ajaxRequest(){
      var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
      if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
       for (var i=0; i<activexmodes.length; i++){
        try{
         return new ActiveXObject(activexmodes[i])
        }
        catch(e){
         //suppress error
        }
       }
      }
      else if (window.XMLHttpRequest) // if Mozilla, Safari etc
       return new XMLHttpRequest()
      else
       return false
     }
    
     var mygetrequest=new ajaxRequest()
    if (mygetrequest.overrideMimeType)
      mygetrequest.overrideMimeType('text/xml')
     mygetrequest.onreadystatechange=function(){
      if (mygetrequest.readyState==4){
       if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
       var xmldata=mygetrequest.responseXML //retrieve result as an XML object
        var rssentries=xmldata.getElementsByTagName("pmdata")
        var output='<ul>'
        for (var i=0; i<rssentries.length; i++){
         output+='<li>'
         output+='<a href="'+rssentries[i].getElementsByTagName('picture')[0].firstChild.nodeValue+'">'
         output+=rssentries[i].getElementsByTagName('name')[0].firstChild.nodeValue+'</a>'
         output+='</li>'
        }
        output+='</ul>'
        document.getElementById("result").innerHTML=output
       }
       else{
        alert("An error has occured making the request")
       }
      }
     }
    
     mygetrequest.open("GET", "http://outranet.scm.tees.ac.uk/users/u0000700/wes_ica_09_10/ukpm.php", true)
     mygetrequest.send(null)

    in php file
    Code:
    <prime_minister>
    <pmdata>
    <name>
    Herbert Henry Asquith
    </name>
    </pmdata>
    <pmdata>
    <dates>
     1908-16
    </dates>
    </pmdata>
    <pmdata>
    <number>
    35
    </number>
    </pmdata>
    <pmdata>
    <picture>
    http://www.number-10.gov.uk/files/images/OLD%20PMs%20-%20H%20H%20Asquith.jpg
    </picture>
    </pmdata>
    </prime_minister>

  • #2
    Fot
    Fot is offline
    Regular Coder
    Join Date
    Mar 2011
    Posts
    111
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Hello, I would like your opinion about my problem.

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    <select name="cs"  onChange="ajaxRequest(this)">
    You are attempting to supply an argument to your ajaxRequest function, but the function doesn't define any arguments.

    Your ajaxRequest function returns an object (or false) which is simply discarded by your onchange event.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    Fot (05-15-2011)


  •  

    Posting Permissions

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