Jquery只使用源代码?

时间:2015-02-11 08:03:02

标签: javascript php jquery html

我有一个html文件,我使用AJAX和PHP动态加载数据。 它们没什么大不了的,因为它们运行良好,但我仍然遇到了问题。 我(为了显示目的)创建了两个div,它们在DOM中显示相同,但​​在源代码中也显示了一个。 (一个div是动态加载的,另一个我已经从开始加载了结果。) 像这样:

<div>
    <ul> 
        <!-- Here is some data which is shown correct -- >
        <!-- (too much to REALLY put it in here -->
    </ul>
</div>
<div id="result">
    <!-- This should show the exact same output, but well isn't... -->
</div>

我已经照顾过一些类似的事情,但没有什么能帮助我解决我的问题,因为我要求&#34;结果&#34;是

function kommissionsakte(o, s) {
    $("#result").empty();
    var xmlHttp = {};
    xmlHttp = ajaxHandler(xmlHttp);

    // Wenn das Objekt erfolgreich erzeugt wurde            
    var url = "ajax/getKommissionsakten.php";

    suchwert = escape($("#suchwert").val());
    var params = "o=" + o + "&s=" + s + "&suchwert=" + suchwert;

    if (suchwert != '') {
        $("#suchwert").css("border-color", "#31ae1c");

        loading();
        xmlHttp.open("POST", url, true);

        //Headerinformationen für den POST Request
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");

        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4) {
                $("#result").html(xmlHttp.responseText);
                closeLoading();
            }
        };
        xmlHttp.send(params);
    } else {
        $("#suchwert").focus();
        $("#suchwert").css("border-color", "#b20e10");
    }
}

我的想法是以某种方式得到#result不是div id而是INTO div,但我很糟糕,所以我不知道怎么做。

编辑:好长说明:

我尝试使用jquery将Filetree加载到已加载的页面中。创建树的代码工作正常,当我尝试将其加载到此页面时它不起作用。我已经读过jquery使用的是DOM而不是源代码,所以它应该正常工作,但它并没有。

我可以在搜索功能中搜索关键字,文件树会显示它们。在手动创建的div中,是Code,它创建了树,jquery正在正确地操作它,如果我现在将完全相同的Code加载到另一个div中,jquery就不会操纵它。

另外我真的很喜欢(就像JS真的很糟糕)所以在答案中有一个很长的解释会非常非常好。

EDIT2: 请求的PHP文件代码:

&#13;
&#13;
<?php
include '../include/ebene.inc.php';
include $ebene.'include/error_reporting.inc.php';
include $ebene.'include/db.inc.php';
include $ebene.'include/getSprache.inc.php';
include $ebene.'include/funktionen-standard.inc.php';
include $ebene.'include/funktionen-individuell.inc.php';
include $ebene.'include/konfig.inc.php';

if(isset($_POST['suchwert'])){
$suchwert =($_POST['suchwert']);
$php_file_tree = '';
$first_call = true;	
$neue_seite = false;

	if($suchwert != ''){
		$parentsql = "SELECT TOP 10 KOM_Nummer from dbo.V_Kommisions_Akte_EN WHERE KOM_Nummer LIKE '%$suchwert%' group by KOM_Nummer";
		$parameter = array();
		$optionen =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
		$parent = sqlsrv_query($dbD3, $parentsql, $parameter, $optionen);
		$parentanzahl = sqlsrv_num_rows($parent);	
		if($parentanzahl != 0){
		$neue_seite = true;
		
				
			if($anzahl >= 200){
			
				echo '<br /><div align="center">'.$var['verfeinern'].'</div>';
			
			}else{
			
				echo '<br /><div align="center">'.$var['anzahl_ergebnisse'].': '.$parentanzahl.'</div>';
				
			}
		$php_file_tree .= "<ul";
		if($first_call) {$php_file_tree .= " class=\"php-file-tree\""; $first_call = false;}
		$php_file_tree .= ">";
		
		
			while($komnr = sqlsrv_fetch_array($parent, SQLSRV_FETCH_ASSOC)) {
			
				$php_file_tree .= "<li class=\"pft-directory\"><a href=\"#\">" . htmlspecialchars($komnr['KOM_Nummer']) . "</a><ul>";
				$komnrregister = $komnr['KOM_Nummer'];
					
				$subsql = "SELECT TOP 10 KOM_Nummer, Register from dbo.V_Kommisions_Akte_EN where KOM_Nummer = '$komnrregister' group by KOM_Nummer, Register";
				$parameter = array();
				$optionen =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
				$sub = sqlsrv_query($dbD3, $subsql, $parameter, $optionen);
				$subanzahl = sqlsrv_num_rows($sub);	
				
				while($register = sqlsrv_fetch_array($sub, SQLSRV_FETCH_ASSOC)) {
				
				
					$php_file_tree .= "<li class=\"pft-directory\"><a href=\"#\">" . htmlspecialchars($register['Register']) . "</a><ul>";
					$registerdokuid = $register['Register'];
					
				$slavesql = "SELECT TOP 10 KOM_Nummer, Register, doku_id from dbo.V_Kommisions_Akte_EN where Register = '$registerdokuid' AND KOM_Nummer = '$komnrregister' group by KOM_Nummer, Register, doku_id";
				$parameter = array();
				$optionen =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
				$slave = sqlsrv_query($dbD3, $slavesql, $parameter, $optionen);
				$slaveanzahl = sqlsrv_num_rows($slave);	
				
					while($doku = sqlsrv_fetch_array($slave, SQLSRV_FETCH_ASSOC)) {
					
						$php_file_tree .= "<li class=\"pft-file ext-xls\"><a href=\"#\">" . htmlspecialchars($doku['doku_id']) . "</a></li>";
						
					}
				$php_file_tree .= '</ul></li>';	
				}	
				$php_file_tree .= '</ul>';
			}
		$php_file_tree .= '</ul>';
		}
	
		echo $php_file_tree;

	//return ($php_file_tree);
	
	
	
	}


}				
?>				
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我的回答需要一些编辑,但你应该尝试这样的事情:

function getMyPage(pageUrl,someData,callback){
    $.ajax({
        type : 'POST',
        url : pageUrl,
        data : {'postName':someData},
        error : function(response){
            console.log("something wrong "+response+" - "+response.responseText+" - "+JSON.stringify(response));
        },
        success : function(response){
            callback(response);
        }
    });
})

然后在代码的某处:

$("body").on("click","#yourButton",getMyPage('http://anything','your data',function(back){
    $("#yourDiv").html(back);
});