Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-20-2011, 05:56 PM   PM User | #1
Fot
Regular Coder

 
Join Date: Mar 2011
Posts: 111
Thanks: 88
Thanked 0 Times in 0 Posts
Fot is an unknown quantity at this point
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>
Fot is offline   Reply With Quote
Old 05-13-2011, 07:04 PM   PM User | #2
Fot
Regular Coder

 
Join Date: Mar 2011
Posts: 111
Thanks: 88
Thanked 0 Times in 0 Posts
Fot is an unknown quantity at this point
Hello, I would like your opinion about my problem.
Fot is offline   Reply With Quote
Old 05-15-2011, 11:52 AM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
Fot (05-15-2011)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:35 PM.


Advertisement
Log in to turn off these ads.