Ajax之后的Javascript

可能重复:
在AJAX请求之前使用JavaScript获取日期

我有一个像这样的Ajax请求:

function ajaxrequest(str){ var aircraft = $("#resultdiv"); aircraft.load("./other_file.php?icao="+str, function(){ }); } 

如果我把Javascript放在other_file.php不行。 我不知道为什么? 但如果使用javascript代码直接工作有趣! 但我需要这个function。 如何使用Javascript工作将乐趣更改为结果?

例如:

如果other_file.php有这个:

  function example(){ var id = document.getElementById('id').value; $("div2").text(id); }  

这不起作用,因为它需要获取var id,但是如果元素具有值2365.javascript代码获取它document.getElementById('id').value; 不起作用因为javascript不起作用。 但是,如果我直接这样做,并且没有functionajaxrequest一切正常。

这实际上包含了other_file.php

  $(function() { $("#editaircraft") .button() .click(function editForm() { }); }); function editForm(){ var icao = document.getElementById('icao').value; var name = document.getElementById('name').value; var weightempty = document.getElementById('weightempty').value; var weightfull = document.getElementById('weightfull').value; var cargofull = document.getElementById('cargofull').value; var cruisespeed = document.getElementById('cruisespeed').value; var range = document.getElementById('range').value; var price = document.getElementById('price').value; var firstclassseats = document.getElementById('firstclassseats').value; var businessclassseats = document.getElementById('businessclassseats').value; var economyclassseats = document.getElementById('economyclassseats').value; ajax.open("POST","edit_aircraft_process.php",true); ajax.onreadystatechange=function(){ if(ajax.readyState==4) { refreshTable(function(){$("#loadingdialog").dialog('close');}); refreshTable(function(){$("#result").fadeIn(); document.getElementById("result").innerHTML=ajax.responseText;}); setTimeout(function() { $("#result").fadeOut() }, 5000); } } ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); ajax.send("icao="+icao+"&name="+name+"&weightempty="+weightempty+"&weightfull="+weightfull+"&cargofull="+cargofull+"&cruisespeed="+cruisespeed+"&range="+range+"&price="+price+"&firstclassseats="+firstclassseats+"&businessclassseats="+businessclassseats+"&economyclassseats="+economyclassseats); $("#editaircraftdialog").dialog('close'); $("#loadingdialog").dialog('open'); }   
<?php echo ''; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo '"; echo '"; echo '"; echo '"; echo '"; echo '"; echo '"; echo '"; if($row["FirstClassSeats"] != NULL && $row["FirstClassSeats"] != 0){ echo '";} if($row["BusinessClassSeats"] != NULL && $row["BusinessClassSeats"] != 0){ echo '";} if($row["EconomyClassSeats"] != NULL && $row["EconomyClassSeats"] != 0){ echo '";} echo ''; } echo "
ICAO:
Name:
Weight Empty:
Weight Full:
Cargo Full:
Cruise Speed:
Range:
Price:
First Class Seats:
Business Class Seats:
Economy Class Seats:
"; ?>

vars的获得是不确定的!

 var aircraft = $("#resultdiv"); function ajaxrequest(str){ $.get("other_file.php?icao="+str, function(result){ aircraft.append(result); }); } 

other_file.php

 ...