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

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 10 votes, 3.60 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-05-2007, 06:08 PM   PM User | #16
rwedge
Regular Coder

 
Join Date: Feb 2005
Posts: 679
Thanks: 0
Thanked 16 Times in 15 Posts
rwedge is on a distinguished road
Again, try it. If you looked at the url you may have noticed the question mark missing just after the URL. I made the change, it will work.

When I tested the response, I was not appending a query string to the URL, just getting a response.
Also added some necessary name handling

Last edited by rwedge; 08-05-2007 at 07:37 PM..
rwedge is offline   Reply With Quote
Old 08-12-2007, 04:56 AM   PM User | #17
rwedge
Regular Coder

 
Join Date: Feb 2005
Posts: 679
Thanks: 0
Thanked 16 Times in 15 Posts
rwedge is on a distinguished road
Wanted to repost as I had a useless extra 'q'
Code:
<script type="text/javascript">
            var xmlHttp
            function GetXmlHttpObject(){
                try{
                    xmlHttp=new XMLHttpRequest();
                }
                catch (e){
                    try{
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch (e){
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                }
                return xmlHttp;
             }
             function stateChanged () {
                 if (xmlHttp.readyState == 4) {
                      if (xmlHttp.status == 200) {
                        alert('Good Response : '+xmlHttp.responseText);
                   } else {
                        alert('Error : '+xmlHttp.statusText);
                     }
                 }
             }
             function addcomment(name,comment,str){
             var q, url = (name || comment)? 'add_comment.php':'add_user_rating.php';
              q = (typeof name != 'undefined')? '?name='+escape(name):'?name='
              if(comment) q+='&comment='+escape(comment) // required entry
              else if (str) q='?rating='+str
              else { alert('Did you forget to enter a comment"');
              return;
             }
              // alert(url+q);  // uncomment to check
              xmlHttp=GetXmlHttpObject()
              if (!xmlHttp){
                   alert("Your browser doesn't support the technology required for this function.")
                   return
               }
              xmlHttp.onreadystatechange=stateChanged
              xmlHttp.open("GET",url+q,true)
              xmlHttp.send(null)
          }
        </script>



<form id="f"  action="" onsubmit="return false">
<p>name:<br />
<input type="text" id="name" value="" size="" maxlength="60" /></p>
<p>Comments:<br />
 <textarea id="comment" cols="25 rows="5" /></textarea></p>
<p>
<select id="rating" size="1" onchange="addcomment('','',this.options[this.selectedIndex].value)">
<option id="a" value="1">1</option>
<option id="b" value="2">2</option>
<option id="c" value="3">3</option>
</select> Rating</p>
<input type="button" id=".btn" value="Submit" onclick="addcomment(form.name.value,form.comment.value,'')" />
</form>
rwedge is offline   Reply With Quote
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 06:00 PM.


Advertisement
Log in to turn off these ads.