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.
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    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.

  2. #17
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    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>


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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