|
|
|
สอบถามเรื่อง get ค่า json มาโชว์หน่อยครับ รบกวนผู้รู้ด้วยนะครับ |
|
|
|
|
|
|
|
ตรงที่ var data ถ้าผมจะให้มันไปเรียกไฟล์jsonเขียนอย่างไรดีครับ
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function() {
var data = [
{
"id": "1",
"name": "test1"},
{
"id": "2",
"name": "test2"}
];
$.each(data, function(i, option) {
$('#sel').append($('<option/>').attr("value", option.id).text(option.name));
});
})
</script>
</head>
<body>
<select id="sel"></select>
</body>
</html>
Tag : MySQL, HTML, JavaScript, Ajax, jQuery
|
|
|
|
|
|
Date :
2017-07-04 18:13:34 |
By :
kimhan1234 |
View :
830 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var obj = jQuery.parseJSON( '{ "name": "John" }' );
|
|
|
|
|
Date :
2017-07-05 09:38:03 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
var string = '[{"title":"Title1"},{"title":"Title2"}]';
var array = JSON.parse(string);
array.forEach(function(object) {
console.log(object.title);
});
|
|
|
|
|
Date :
2017-07-05 09:38:28 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
$(function() {
$.ajax({ url: '/datajson.json'}).done(function(msg){
var data = $.parseJSON(msg);
$.each(data, function(i, option) {
$('#sel').append($('<option/>').attr("value", option.id).text(option.name));
});
})
})
|
|
|
|
|
Date :
2017-07-05 09:50:39 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2017-07-05 18:10:31 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|