www.webdeveloper.com
Results 1 to 11 of 11

Thread: ajax problem

  1. #1
    Join Date
    Aug 2013
    Posts
    8

    Unhappy ajax problem

    iam using form to add new target to user
    i need when he choose from menu without refresh page the information about this record show in text (chained select)
    i'm using ajax but code have error i don't know it
    code for part_a_new

    HTML Code:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Part A</title>
    <style type="text/css">
    body {
    	background-image: url(images/background.png);
    }
    </style>
    <script type="text/javascript" language="javascript" src="css/jquery2.js"></script>
    
    <script language="javascript" type="text/javascript">
    function getXMLHTTP() { //fuction to return the xml http object
    		var xmlhttp=false;	
    		try{
    			xmlhttp=new XMLHttpRequest();
    		}
    		catch(e)	{		
    			try{			
    				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
    			}
    			catch(e){
    				try{
    				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    				}
    				catch(e1){
    					xmlhttp=false;
    				}
    			}
    		}
    		 	
    		return xmlhttp;
        }
    	
    	function getMake(id) {		
    		
    		var strURL="findmake.php?id="+id;
    		var req = getXMLHTTP();
    		
    		if (req) {
    			
    			req.onreadymakechange = function() {
    				if (req.readyMake == 4) {
    					// only if "OK"
    					if (req.status == 200) {						
    						document.getElementById('makediv').innerHTML=req.responseText;						
    					} else {
    						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    					}
    				}				
    			}			
    			req.open("GET", strURL, true);
    			req.send(null);
    		}		
    	}
    	function getMake(id) {		
    		var strURL="findlast.php?id="+id;
    		var req = getXMLHTTP();
    		
    		if (req) {
    			
    			req.onreadymakechange = function() {
    				if (req.readyState == 4) {
    					// only if "OK"
    					if (req.status == 200) {						
    						document.getElementById('lastdiv').innerHTML=req.responseText;						
    					} else {
    						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    					}
    				}				
    			}			
    			req.open("GET", strURL, true);
    			req.send(null);
    		}
    				
    	}
    </script>
    </head>
    <body>
    <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
     <table align="center">
    <td nowrap="nowrap" align="right">Substation_name:</td>
          <td><select name="substation_name" onChange="getmake(this.value)">
            <?php
    do {  
    ?>
            <option value="<?php echo $row_substation['id']?>"><?php echo $row_substation['station']?></option>
            <?php
    } while ($row_substation = mysql_fetch_assoc($substation));
      $rows = mysql_num_rows($substation);
      if($rows > 0) {
          mysql_data_seek($substation, 0);
    	  $row_substation = mysql_fetch_assoc($substation);
      }
    ?>
          </select></td>
        </tr>
        <tr> </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Make:</td>
          <td><div id="makediv"><select name="make">
            	<option> </option>
          </select></div></td>
        </tr>
        <tr> </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Prev_MTC:</td>
      <td><div id="lastdiv"><select name="last">
                   	<option> </option>
          </select></div></td>
    </table>
    <body>
    code for findmake.php
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php $make=intval($_GET['id']);
    $link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('trsh');
    $query="SELECT id,make FROM substations WHERE id ='$make'";
    $result=mysql_query($query);
    
    ?>
    <select name="make" onchange="getMake(<?php echo $make ?>,this.value)">
      <option></option>
      <?php while($row=mysql_fetch_array($result)) { ?>
      <option value><?php echo $row['make']?></option>
      <?php } ?>
    </select>
    </body>
    </html>
    code for findlast.php

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php $last=intval($_GET['id']);
    $link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('trsh');
    $query="SELECT id,last FROM substations WHERE id ='$last'";
    $result=mysql_query($query);
    
    ?>
    <select name="last" onchange="getMake(<?php echo $last ?>,this.value)">
      <option></option>
      <?php while($row=mysql_fetch_array($result)) { ?>
      <option value><?php echo $row['last']?></option>
      <?php } ?>
    </select>
    
    </body>
    </html>
    database
    new:
    id,station,make,last,foward,user,date
    station:
    id,station,make,last

    we bring data fron station to but in new and complete information

    plz help me

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    703
    try running your ajax script separately until you get it debugged. It's easier to find the errors that way

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,346
    Try using http://www.jibbering.com/2002/4/httprequest.html XML Http object

    The other method is to use the work around method for making an XMLHttpRequest Object

    Code:
    /*
       Provide the XMLHttpRequest constructor for Internet Explorer 5.x-6.x:
       Other browsers (including Internet Explorer 7.x-9.x) do not redefine
       XMLHttpRequest if it already exists.
     
       This example is based on findings at:
       http://blogs.msdn.com/xmlteam/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx
    */
    if (typeof XMLHttpRequest === "undefined") {
      XMLHttpRequest = function () {
        try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
        catch (e) {}
        try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
        catch (e) {}
        try { return new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (e) {}
        throw new Error("This browser does not support XMLHttpRequest.");
      };
    }
    which if browser supports XMLHttpRequest then its ignored but if no XMLHttpRequest object exist then it is created.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  4. #4
    Join Date
    Aug 2013
    Posts
    8
    how can i try my code separately??? i'm using dreamweaver cs5 can i try in it?? how can i do??
    thank you

  5. #5
    Join Date
    Aug 2013
    Posts
    8
    Quote Originally Posted by \\.\ View Post
    Try using http://www.jibbering.com/2002/4/httprequest.html XML Http object

    The other method is to use the work around method for making an XMLHttpRequest Object

    Code:
    /*
       Provide the XMLHttpRequest constructor for Internet Explorer 5.x-6.x:
       Other browsers (including Internet Explorer 7.x-9.x) do not redefine
       XMLHttpRequest if it already exists.
     
       This example is based on findings at:
       http://blogs.msdn.com/xmlteam/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx
    */
    if (typeof XMLHttpRequest === "undefined") {
      XMLHttpRequest = function () {
        try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
        catch (e) {}
        try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
        catch (e) {}
        try { return new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (e) {}
        throw new Error("This browser does not support XMLHttpRequest.");
      };
    }
    which if browser supports XMLHttpRequest then its ignored but if no XMLHttpRequest object exist then it is created.
    iam try this code and remove old one about calling XMLHttpRequest Object but still not work
    i need to know how can i try my code separately to know errors

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    703
    When I write a php script that ultimately will be called via some ajax code, I debug the php script itself before calling it with the ajax code.

    Simply run it with the same url that you would compose from your ajax code. The echos that you return to the ajax caller will simply be shown on screen and you can make additional lines to help you debug it, then remove them once it is working.

    Not rocket science.

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,346
    If you are having an Ajax problem you should ask in the Javascript forum, you will also find plenty of Ajax examples on how to use, create and process these suite of functions.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  8. #8
    Join Date
    Aug 2013
    Posts
    8
    thank you my friends i will post my proplem in javascript forum please clost this >>> proplem not solve

    Notice: Undefined index: id in C:\wamp\www\trsh\part_a_new.php on line 230
    Notice: Undefined index: id in C:\wamp\www\trsh\part_a_new.php on line 249
    !!!
    i will try in javascript forum thank you

  9. #9
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,346
    Unless you can post the entire code so someone can look at the script to see what lines 230 and 249 are and work out what line the actual error is on, no one can assist you with that error.

    An error can occur at a point a few lines before the interpreter grinds to a halt and gives up. It then reports where it ended interpreting, in the case of PHP this is a little more accurate as lines generally do point to those lines but again its a case of the interpreter continues processing until it then gives up, issues an error before carrying on at the next piece of readable code.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  10. #10
    Join Date
    Aug 2013
    Posts
    8
    my friend


    iam fix proplem with this code

    <option value="<?php echo $row_station['id']?>"> <?php echo $row_station['station']?> </option>

    <script> $("#selectstation").change(function (){
    var VALUESTATION = $("#selectstation").val();
    $("#makediv").load("findmake.php?id="+VALUESTATION);
    $("#lastdiv").load("findlast.php?id="+VALUESTATION);
    //alert(VALUESTATION);
    });
    </script>

    but how can i get label not value ineed to get name not id can any one help me??

  11. #11
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,346
    The problem you have is that you are expecting a whole implementation to work and resorting to using Jquery is not a way of solving problems.

    Frameworks may be a popular way of getting code completed but you are reliant on loading the entire library when you only need several lines of code from a function.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles