probleem met parsen van json uit iframe
Het probleem is dat de json uit mijn iframe niet doorkomt in de parse functie van mijn js
iemand suggesties
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?
/* UPLOAD PROGRESS CODE */
function attachUploadHandlers()
{
$("#upload_form_events").submit(function()
{
var id = $(this).find('#UPLOAD_IDENTIFIER').val();
cur_upload_id = id;
$(this).attr('id', id);
beginUpload(id);
if ($.browser.msie)
$("#adminImage").bind('readystatechange', completeUpload);
else
$("#adminImage").bind('load', completeUpload);
});
$("#upload_form_events2").submit(function()
{
var id = $(this).find('#UPLOAD_IDENTIFIER').val();
cur_upload_id = id;
$(this).attr('id', id);
beginUpload(id);
if ($.browser.msie)
$("#adminImage").bind('readystatechange', completeUpload);
else
$("#adminImage").bind('load', completeUpload);
});
}
function beginUpload(id)
{
uploading = true;
$("#"+id+" #loadgif").html('<img class="loading_showmore" src="<?php echo Settings::$url; ?>/images/ajax_loader.gif">');
getUploadProgress(id);
return true;
}
function getUploadProgress()
{
var timestamp = new Date().getTime();
if(uploading)
{
/*$.get(
"<?php echo Settings::$url;?>/report-progress.php",
{ id: upload_id, t: timestamp }
);*/
}
if(uploading)
{
window.setTimeout(getUploadProgress, 500);
}
}
function completeUpload(ev)
{
if(uploading && ( ev.type && ( ev.type == 'load' || ev.type == "readystatechange" ) ) )
{
//Terug gegeven data opvangen
var kind = '#'+cur_upload_id+' .admin_events_upload_image';
var type = 'image';
//iframe data ophalen
var data = $('#adminImage').contents().find('body').text();
var file = $.parseJSON(data);
if(file['check'])
{
var text = file['filename']+' <span id="file">X</span>';
eventObject.image = file['filenameNew'];
$(kind).fadeOut(1000).next('span').html(text).delay(1000).fadeIn(2000);
}
else
{
$('.admin_errors').html(file['error']);
$('.admin_errors').show();
clearFileInputField("fileImageDiv");
}
$('#file').click(function()
{
$(this).parent().fadeOut(1000).prev('.buttonGrey').delay(1000).fadeIn(2000).val('');
eventObject.image = '';
clearFileInputField("fileImageDiv");
});
uploading = false;
$("#loadgif").empty();
}
}?>
/* UPLOAD PROGRESS CODE */
function attachUploadHandlers()
{
$("#upload_form_events").submit(function()
{
var id = $(this).find('#UPLOAD_IDENTIFIER').val();
cur_upload_id = id;
$(this).attr('id', id);
beginUpload(id);
if ($.browser.msie)
$("#adminImage").bind('readystatechange', completeUpload);
else
$("#adminImage").bind('load', completeUpload);
});
$("#upload_form_events2").submit(function()
{
var id = $(this).find('#UPLOAD_IDENTIFIER').val();
cur_upload_id = id;
$(this).attr('id', id);
beginUpload(id);
if ($.browser.msie)
$("#adminImage").bind('readystatechange', completeUpload);
else
$("#adminImage").bind('load', completeUpload);
});
}
function beginUpload(id)
{
uploading = true;
$("#"+id+" #loadgif").html('<img class="loading_showmore" src="<?php echo Settings::$url; ?>/images/ajax_loader.gif">');
getUploadProgress(id);
return true;
}
function getUploadProgress()
{
var timestamp = new Date().getTime();
if(uploading)
{
/*$.get(
"<?php echo Settings::$url;?>/report-progress.php",
{ id: upload_id, t: timestamp }
);*/
}
if(uploading)
{
window.setTimeout(getUploadProgress, 500);
}
}
function completeUpload(ev)
{
if(uploading && ( ev.type && ( ev.type == 'load' || ev.type == "readystatechange" ) ) )
{
//Terug gegeven data opvangen
var kind = '#'+cur_upload_id+' .admin_events_upload_image';
var type = 'image';
//iframe data ophalen
var data = $('#adminImage').contents().find('body').text();
var file = $.parseJSON(data);
if(file['check'])
{
var text = file['filename']+' <span id="file">X</span>';
eventObject.image = file['filenameNew'];
$(kind).fadeOut(1000).next('span').html(text).delay(1000).fadeIn(2000);
}
else
{
$('.admin_errors').html(file['error']);
$('.admin_errors').show();
clearFileInputField("fileImageDiv");
}
$('#file').click(function()
{
$(this).parent().fadeOut(1000).prev('.buttonGrey').delay(1000).fadeIn(2000).val('');
eventObject.image = '';
clearFileInputField("fileImageDiv");
});
uploading = false;
$("#loadgif").empty();
}
}?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
$arr['html'] = '
<div class="admin_events_wrapper">
<div class="admin_events_input_item">
<span class="admin_events">Titel </span>
<input class="admin_events" id="txtTitle" type="text" name="txtTitle"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Datum van event </span>
<input class="admin_events date" id="txtEventDate" type="text" name="txtEventDate" />
</div>
<div class="admin_events_input_item">
<span class="admin_events">Datum plaatsing (website) </span>
<input class="admin_events date" type="text" name="txtPlacementDate" />
</div>
<div class="admin_events_input_item">
<span class="admin_events">Website </span>
<input class="admin_events not-required" type="text" name="txtWebsite"/>
</div>
<form target="upload_form_events" id="upload_form_events" action="'.Settings::$url.'/admin/fileupload.php" method="post" enctype="multipart/form-data">
<div class="admin_events_input_item">
<input type="hidden" id="UPLOAD_IDENTIFIER" name="UPLOAD_IDENTIFIER" value="'.uniqid("upload").'" />
<input type="hidden" id="UPLOAD_TYPE" name="UPLOAD_TYPE" value="events_image"/>
<span class="admin_events">Afbeelding </span>
<div id="fileImageDiv" class="admin_events_upload_image buttonGrey">
<span> Afbeelding selecteren…</span>
<input class="opacity" type="file" id="fileImage" name="fileImage" />
</div>
<span id="imageDisplay" class="displayNone"></span>
<div class="infoSpan" id="loadgif"></div>
</div>
</form>
<form target="upload_form_events" id="upload_form_events" action="'.Settings::$url.'/admin/fileupload.php" method="post" enctype="multipart/form-data">
<div class="admin_events_input_item">
<input type="hidden" id="UPLOAD_IDENTIFIER" name="UPLOAD_IDENTIFIER" value="'.uniqid("upload").'" />
<input type="hidden" id="UPLOAD_TYPE" name="UPLOAD_TYPE" value="events_sliderfoto"/>
<span class="admin_events">Eventslider foto</span>
<div id="fileImageDiv2" class="admin_events_upload_image buttonGrey">
<span> Afbeelding selecteren…</span>
<input class="opacity" type="file" id="fileImage2" name="fileImage2" />
</div>
<span id="imageDisplay" class="displayNone"></span>
<div class="infoSpan" id="loadgif"></div>
</div>
</form>
<div class="admin_events_input_item">
<span class="admin_events">Uitgelicht (slider)</span>
<input class="admin_events_checkbox" type="checkbox" name="chkFeatured" />
</div>
<div class="admin_events_input_item">
<span class="admin_events">Google Maps</span>
<input class="admin_events_checkbox" type="checkbox" name="chkMaps" />
</div>
<div class="mapToggle">
<div class="admin_events_input_item">
<span class="admin_events">Adres </span>
<input class="admin_events" type="text" name="txtAddress"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Huisnummer </span>
<input class="admin_events" type="text" name="txtStreetNumber"/>
</div>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Locatie </span>
<input class="admin_events" id="txtLocation" type="text" name="txtLocation"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Beschikbare plaatsen </span>
<input class="admin_events" id="txtPlaces" type="text" name="txtPlaces"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Extern beschikbaar</span>
<input class="admin_events_checkbox" type="checkbox" name="chkExtern" />
</div>
<div class="ExternToggle">
<div class="admin_events_input_item">
<span class="admin_events">Url prefix</span>
<input class="admin_events not-required" type="text" name="txtUrlPrefix" value="'.$data[0]['extern_url'].'"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events"><b>Voorbeeld:</b></span>
<span class="admin_events example"></span>
</div>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Beschrijving</span>
<div class="admin_events_textarea">
<textarea class="required" id="txtDescription" name="txtDescription"></textarea><input type="button" name="submit" id="descriptionShow" value="Weergeven" />
</div>
</div>
<div class="example" style="margin-bottom: 15px; float: left;">
<span class="admin_events">Voorbeeld</span>
<div class="example_box" style="padding: 20px; border: 1px solid #CCCCCC; float: left">
<div class="kopBlack" style="min-height: 16px;"><span class="txtTitle"></span></div>
<div class="events_info">
<div class="events_info_left">
<div class="events_info_specific">
<div class="events_info_item"><span>Datum</span> | <span style="font-weight: normal;" class="txtEventDate"></span></div>
<div class="events_info_item"><span>Locatie</span> | <span style="font-weight: normal;" class="txtLocation"></span></div>
<div class="events_info_item"><span>Aantal beschikbare plaatsen</span> | <span style="font-weight: normal;" class="txtPlaces"></span></div>
</div>
</div>
<div class="events_info_right">
<div id="50" class="buttonbox cancel">
<div class="box_head">Afmelden</div>
</div>
</div>
</div>
<div class="events_further_info">
<div class="events_title_left">Informatie</div>
<div class="events_info_tekst"><span class="txtDescription"></span></div>
</div>
</div>
</div>
<div class="admin_events_input_item">
<div class="admin_events_button sendForm buttonGrey">Plaats</div>
<div class="admin_events_button back buttonGrey">Terug</div>
</div>
<div id="mapLocation"></div>
</div>
<iframe class="displayNone" id="adminImage" src="'.Settings::$url.'/leeg.html" name="upload_form_events"></iframe>';
?>
$arr['html'] = '
<div class="admin_events_wrapper">
<div class="admin_events_input_item">
<span class="admin_events">Titel </span>
<input class="admin_events" id="txtTitle" type="text" name="txtTitle"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Datum van event </span>
<input class="admin_events date" id="txtEventDate" type="text" name="txtEventDate" />
</div>
<div class="admin_events_input_item">
<span class="admin_events">Datum plaatsing (website) </span>
<input class="admin_events date" type="text" name="txtPlacementDate" />
</div>
<div class="admin_events_input_item">
<span class="admin_events">Website </span>
<input class="admin_events not-required" type="text" name="txtWebsite"/>
</div>
<form target="upload_form_events" id="upload_form_events" action="'.Settings::$url.'/admin/fileupload.php" method="post" enctype="multipart/form-data">
<div class="admin_events_input_item">
<input type="hidden" id="UPLOAD_IDENTIFIER" name="UPLOAD_IDENTIFIER" value="'.uniqid("upload").'" />
<input type="hidden" id="UPLOAD_TYPE" name="UPLOAD_TYPE" value="events_image"/>
<span class="admin_events">Afbeelding </span>
<div id="fileImageDiv" class="admin_events_upload_image buttonGrey">
<span> Afbeelding selecteren…</span>
<input class="opacity" type="file" id="fileImage" name="fileImage" />
</div>
<span id="imageDisplay" class="displayNone"></span>
<div class="infoSpan" id="loadgif"></div>
</div>
</form>
<form target="upload_form_events" id="upload_form_events" action="'.Settings::$url.'/admin/fileupload.php" method="post" enctype="multipart/form-data">
<div class="admin_events_input_item">
<input type="hidden" id="UPLOAD_IDENTIFIER" name="UPLOAD_IDENTIFIER" value="'.uniqid("upload").'" />
<input type="hidden" id="UPLOAD_TYPE" name="UPLOAD_TYPE" value="events_sliderfoto"/>
<span class="admin_events">Eventslider foto</span>
<div id="fileImageDiv2" class="admin_events_upload_image buttonGrey">
<span> Afbeelding selecteren…</span>
<input class="opacity" type="file" id="fileImage2" name="fileImage2" />
</div>
<span id="imageDisplay" class="displayNone"></span>
<div class="infoSpan" id="loadgif"></div>
</div>
</form>
<div class="admin_events_input_item">
<span class="admin_events">Uitgelicht (slider)</span>
<input class="admin_events_checkbox" type="checkbox" name="chkFeatured" />
</div>
<div class="admin_events_input_item">
<span class="admin_events">Google Maps</span>
<input class="admin_events_checkbox" type="checkbox" name="chkMaps" />
</div>
<div class="mapToggle">
<div class="admin_events_input_item">
<span class="admin_events">Adres </span>
<input class="admin_events" type="text" name="txtAddress"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Huisnummer </span>
<input class="admin_events" type="text" name="txtStreetNumber"/>
</div>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Locatie </span>
<input class="admin_events" id="txtLocation" type="text" name="txtLocation"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Beschikbare plaatsen </span>
<input class="admin_events" id="txtPlaces" type="text" name="txtPlaces"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Extern beschikbaar</span>
<input class="admin_events_checkbox" type="checkbox" name="chkExtern" />
</div>
<div class="ExternToggle">
<div class="admin_events_input_item">
<span class="admin_events">Url prefix</span>
<input class="admin_events not-required" type="text" name="txtUrlPrefix" value="'.$data[0]['extern_url'].'"/>
</div>
<div class="admin_events_input_item">
<span class="admin_events"><b>Voorbeeld:</b></span>
<span class="admin_events example"></span>
</div>
</div>
<div class="admin_events_input_item">
<span class="admin_events">Beschrijving</span>
<div class="admin_events_textarea">
<textarea class="required" id="txtDescription" name="txtDescription"></textarea><input type="button" name="submit" id="descriptionShow" value="Weergeven" />
</div>
</div>
<div class="example" style="margin-bottom: 15px; float: left;">
<span class="admin_events">Voorbeeld</span>
<div class="example_box" style="padding: 20px; border: 1px solid #CCCCCC; float: left">
<div class="kopBlack" style="min-height: 16px;"><span class="txtTitle"></span></div>
<div class="events_info">
<div class="events_info_left">
<div class="events_info_specific">
<div class="events_info_item"><span>Datum</span> | <span style="font-weight: normal;" class="txtEventDate"></span></div>
<div class="events_info_item"><span>Locatie</span> | <span style="font-weight: normal;" class="txtLocation"></span></div>
<div class="events_info_item"><span>Aantal beschikbare plaatsen</span> | <span style="font-weight: normal;" class="txtPlaces"></span></div>
</div>
</div>
<div class="events_info_right">
<div id="50" class="buttonbox cancel">
<div class="box_head">Afmelden</div>
</div>
</div>
</div>
<div class="events_further_info">
<div class="events_title_left">Informatie</div>
<div class="events_info_tekst"><span class="txtDescription"></span></div>
</div>
</div>
</div>
<div class="admin_events_input_item">
<div class="admin_events_button sendForm buttonGrey">Plaats</div>
<div class="admin_events_button back buttonGrey">Terug</div>
</div>
<div id="mapLocation"></div>
</div>
<iframe class="displayNone" id="adminImage" src="'.Settings::$url.'/leeg.html" name="upload_form_events"></iframe>';
?>
Een beetje een vreemde naam voor een bestand waar je informatie uit wil halen.
Maar dus, die leeg.html bevat een <body>. Alles binnen die <body> is tekst die door JSON kan geparset worden.
Dus bv.
<body>{fruit: ['appel', 'peer', 'citroen'], groente: ['wortel', 'raap']}</body>
Klopt dit nog?
Dan kunnen we zien of de code voorbij lijnen 69/701 raken.
----
Denk je niet dat het beter zou zijn om dit alles niet met iframes te doen?
JSON informatie lezen op een iframe ... het klinkt als "iets heel nieuw doen met heel erg oud materiaal" (zoek zelf maar een flauwe analogie, ik heb geen inspiratie)
De meeste hier hebben waarschijnlijk nog nooit JSON gebruikt met Ajax; jij gebruikt het met een iframe ...
dat is waar ik gebruik het op een iframe maar het moet werken
Of steekt daar nog iets anders? Indien daar nog iets anders steekt, zal parseJSON sowieso falen.