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'); }
vars的获得是不确定的!
var aircraft = $("#resultdiv"); function ajaxrequest(str){ $.get("other_file.php?icao="+str, function(result){ aircraft.append(result); }); }
other_file.php
...
- 如何在保留reCaptcha脚本的同时使用jQuery / AJAX加载reCaptcha表单?
- 使用jQueryvalidation的ASP.Net MVC Ajax表单
- 使用jQuery和Ajax进行远程POST请求
- jQuery无法将类添加到动态添加的内容中
- 使用ajax和jquery发送数据 – textarea.live(’blur’)
- Ajax加载栏function
- 在$ .POST上获取ERR_EMPTY_RESPONSE
- 在Safari 10.13.4中发送包含空文件输入的FormData()时,AJAX请求失败
- 如何通过ajax将JSON数据传递给restful web服务以及如何获取JSON数据?