가능한 중복 후 :
Obtain dates with JavaScript before AJAX request자바 스크립트 아약스
이 같은 Ajax 요청이 있습니다
function ajaxrequest(str){
var aircraft = $("#resultdiv");
aircraft.load("./other_file.php?icao="+str, function(){
});
}
나는 other_file.php don'에서 자바 스크립트를 넣어 경우 작동합니다. 왜 그런지 몰라? 하지만 자바 스크립트 코드를 직접 사용하면 재미있게 작동합니다! 하지만 기능이 필요합니다. 어떻게 Javascript로 재미있는 결과를 얻을 수 있습니까? 예를 들어
:
이이 other_file.php 경우
<script>
function example(){
var id = document.getElementById('id').value;
$("div2").text(id);
}
</script>
이 본건 공사는 VAR ID를 얻을 필요하지만 때문에 요소의 값은 2365. 자바 스크립트가있는 경우 그것을 얻으려면 코드 document.getElementById('id').value;
javascript 작동하지 않기 때문에 작동하지 않습니다. 하지만이 작업을 ajaxrequest 함수로 직접 수행하면 아무 문제가 없습니다.
이것은 정말 바르의 얻이 undefinid있는
<script>
$(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');
}
</script>
<?php
require_once ('../../config.php');
$icao = $_REQUEST["icao"];
$query = "SELECT * FROM aircrafts WHERE ICAO = '$icao'";
$result = mysql_query($query);
if (!$result)
{
die (mysql_error());
}
?>
<form action="javascript:editForm();" method="post" enctype="application/x-www-form-urlencoded">
<?php
echo '<table border="0">';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo '<tr><td class="forms">ICAO:</td><td><input type="text" id="icao" name="icao" size="30" value=';
echo $row["ICAO"] . "></td></tr>";
echo '<tr><td class="forms">Name:</td><td><input type="text" id="name" name="name" size="30" value=';
echo $row["Name"] . "></td></tr>";
echo '<tr><td class="forms">Weight Empty:</td><td><input type="text" id="weightempty" name="weightempty" size="30" value=';
echo $row["WeightEmpty"] . "></td></tr>";
echo '<tr><td class="forms">Weight Full:</td><td><input type="text" id="weightfull" name="weightfull" size="30" value=';
echo $row["WeightFull"] . "></td></tr>";
echo '<tr><td class="forms">Cargo Full:</td><td><input type="text" id="cargofull" name="cargofull" size="30" value=';
echo $row["CargoFull"] . "></td></tr>";
echo '<tr><td class="forms">Cruise Speed:</td><td><input type="text" id="cruisespeed" name="cruisespeed" size="30" value=';
echo $row["CruiseSpeed"] . "></td></tr>";
echo '<tr><td class="forms">Range:</td><td><input type="text" id="range" name="range" size="30" value=';
echo $row["Range"] . "></td></tr>";
echo '<tr><td class="forms">Price:</td><td><input type="text" id="price" name="price" size="30" value=';
echo $row["Price"] . "></td></tr>";
if($row["FirstClassSeats"] != NULL && $row["FirstClassSeats"] != 0){
echo '<tr><td class="forms">First Class Seats:</td><td><input type="text" id="firstclassseats" name="firstclassseats" size="30" value=';
echo $row["FirstClassSeats"] . "></td></tr>";}
if($row["BusinessClassSeats"] != NULL && $row["BusinessClassSeats"] != 0){
echo '<tr><td class="forms">Business Class Seats:</td><td><input type="text" id="businessclassseats" name="businessclassseats" size="30" value=';
echo $row["BusinessClassSeats"] . "></td></tr>";}
if($row["EconomyClassSeats"] != NULL && $row["EconomyClassSeats"] != 0){
echo '<tr><td class="forms">Economy Class Seats:</td><td><input type="text" id="economyclassseats" name="economyclassseats" size="30" value=';
echo $row["EconomyClassSeats"] . "></td></tr>";}
echo '<tr><td><input id="editaircraft" type="submit" value="Edit Aircraft"></td></tr>';
}
echo "</table>";
?>
</form>
other_file.php
의 포함입니다!
, 더 많은 코드를 제공, 우리가 정말 내가 뭔가 일을하지는 – intuitivepixel