0
的jsfiddle jQuery的AJAX功能,我有內點擊數 不工作的onLoad
- 它的工作原理的jQuery的AJAX功能,它不會在最初的頁面加載工作。
這是可能的還是我錯過了什麼?
這裏是的jsfiddle:
http://jsfiddle.net/djlerman/bbj8k9pe/
我試圖延遲選項,但沒有解決問題。
// Run ajax function onLoad -- DOESN'T WORK
getNodeViaAjax();
// Run ajax function ON Button click -- WORKS
$("#buttonID").on("click", "", function() {
getNodeViaAjax();
});
// ajax function
function getNodeViaAjax() {
$.ajax({
\t \t type: 'POST',
url: '/echo/json/',
data: {
json: JSON.stringify(jsonData)
},
success: function(data) {
$('#displayResponse').html(JSON.stringify(data));
},
error:function(error){
alert('there was an error');
},
dataType: 'json'
});
}
// Data to return via ajax
/* This is an echo of some data sent back via ajax */
/* This data should be filtered by nodeID and return only childNodeID's. */
/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv. */
var jsonData = {
"nodeID": {
"1": {
"childNodeID": {
"1.1": {
"childNodeType": "branch",
"childData": [
"1.1: column 1",
"1.1: column 2"
]
},
"1.2": {
"childNodeType": "leaf",
"childData": [
"1.2: column 1",
"1.2: column 2"
]
},
"1.3": {
"childNodeType": "leaf",
"childData": [
"1.3: column 1",
"1.3: column 2"
]
}
}
},
"1.1": {
"childNodeID": {
"1.1.1": {
"childNodeType": "leaf",
"childData": [
"1.1.1: column 1",
"1.1.1: column 2"
]
},
"1.1.2": {
"childNodeType": "leaf",
"childData": [
"1.1.2: column 1",
"1.1.2: column 2"
]
}
}
},
"2": {
"childNodeID": {
"2.1": {
"childNodeType": "leaf",
"childData": [
"2.1: column 1",
"2.1: column 2"
]
},
"2.2": {
"childNodeType": "leaf",
"childData": [
"2.2: column 1",
"2.2: column 2"
]
},
"2.3": {
"childNodeType": "leaf",
"childData": [
"2.3: column 1",
"2.3: column 2"
]
}
}
}
}
};
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
/* This is an echo of some data sent back via ajax */
/* This data should be filtered by nodeID and return only childNodeID's. */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<button id="buttonID">Click to Load ajax</button>
<div id="displayResponse"></div>
http://jsfiddle.net/bbj8k9pe/4/ – guest271314