我想傳遞動態ID和你的AJAX調用。我已經創建了一個基本的div結構,並希望從不同的url中加載相同的結構中的數據,並且還希望div使用不同的id複製自己,以便可以顯示具有相同結構但不同數據和id的多個div。我寫了代碼,但不幸的是它顯示來自不同網址的數據在同一個div和其他divs顯示空數據。我正在上傳一個代碼片段,但在這一點上,我只能提供靜態ID。將動態ID和URL傳遞給AJAX調用
$(function(){
var camera, renderer;
var mpi=Math.PI /180;
var circleRadius = 1800;
var startAngle = 0;
var centerX = 0;
var centerZ = 0;
var startRadians = startAngle + mpi;
var totalSpheres = 5;
var incrementAngle = 360/totalSpheres;
var incrementRadians = incrementAngle * mpi;
var Element = function (id, w, h, position, rotation) {
var html = [
'<div class="wrapper" >',
'<ul class="stage clearfix">',
'<li class="scene" >',
'<div class="movie i1" id="' + id + '" >',
'</div>',
'</li>',
'</ul>',
'</div>'
].join('\n');
var div = document.createElement('div');
$(div).html(html);
var object = new THREE.CSS3DObject(div);
object.position.x = position.x;
object.position.y = position.y;
object.position.z = position.z;
object.rotation.x = rotation.x;
object.rotation.y = rotation.y;
object.rotation.z = rotation.z;
return object;
}
init();
function init() {
scene = new THREE.Scene();
var container = document.getElementById('container');
var renderer = new THREE.CSS3DRenderer();
renderer.setSize(window.innerWidth, window.innerHeight*.85);
container.appendChild(renderer.domElement);
camera = new THREE.PerspectiveCamera(50, window.innerWidth/window.innerHeight, 1, 10);
camera.position.set(-100,60,4000);
var group = new THREE.Group();
var str = {
"0":"attacker",
"1":"defender",
}
for (var i = 0; i < totalSpheres; i ++) {
$.ajax({
dataType: "text",
url: "http://localhost/liberate/threeee/PAGES/Information/content.html",
success: function (data) {
console.log(data);
$(str[i]).append(data)
}});
}
for (var i = 0; i < totalSpheres; i ++) {
var xp = centerX + Math.sin(startRadians) * circleRadius;
var zp = centerZ + Math.cos(startRadians) * circleRadius;
group.add(new Element(str, 1000, 1000, new THREE.Vector3(xp, 0, zp), new THREE.Vector3(0, i*incrementAngle * (Math.PI/180.0), 0)));
startRadians += incrementRadians;
}
scene.add(group);
renderer.render(scene, camera);
}
});
我試圖動態ID,並試圖調試代碼,但它顯示Object對象在id.Can有人給什麼可以在這種情況下完成的任何建議。
你通過ajax發送任何東西。 –
但是,如果我什麼都沒有發送,那麼我怎麼才能看到控制檯中的數據 –
你正在傳遞'str'作爲id,這是一個對象。相反,你可能只想傳遞'我'(我不知道你想用什麼id)。 –