Forum Moderators: open
This works perfectly in Firefox. The problem I am having is that in Safari, nothing happens when a past article is selected from the dropdown. By printing out the xhr.responseText, I have figured out that in Safari, the responseText isn't being completed. In Safari I get:
$('newTitle').value = "title I selected"; $('newNewsID').value = "4973"; blurb = FCKeditorAPI.GetInstance('blurb'); blurb.SetHTML("first paragraph" ...there should be more here (the other paragraph(s))
In Firefox I get what I should:
$('newTitle').value = "title I selected"; $('newNewsID').value = "4973"; blurb = FCKeditorAPI.GetInstance('blurb'); blurb.SetHTML("first paragraph.
last paragraph."); $('newLink').value = "url to news release";
So, for some reason, in Safari responseText stops being generated when there is a newline? Or when there is a blank line anyway. I don't understand why this would work fine in FF but not in Safari.
Here is the code for this:
news.js:
function loadNewsRelease() {
new Ajax.Request(url+'news_handler.php', {
method: 'get',
parameters: { newsId: $('chooseNews').value },
onSuccess: function(xhr) {
eval(xhr.responseText);
},
onFailure: function(xhr) {
alert("Error "+xhr.status+": "+xhr.statusText);
$('chooseNews').value = 0;
}
});
}
news_handler.php:
$conn = mysql_connect(dbInfo) or die(mysql_error());
mysql_select_db("dbName", $conn);
if (isset($_GET['newsId'])) {
$query = sprintf('SELECT title, content FROM newsrelease WHERE id = \'%d\'', $_GET['newsId']);
$res = mysql_query($query, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res);
if (!$row && $_GET['newsId'] != 0): ?>
alert('News #<?=$_GET['newsId']?> does not exist.');
<? else: ?>
<? if (!$row) $row = array('title' => '', 'content' => ''); ?>
<?
$blurbArray = split("\n", $row['content']);
$blurbArray = array_filter($blurbArray, 'notBlank');
$keys = array_keys($blurbArray);
$blurb = @$blurbArray[$keys[0]] .'<br /><br />'. @$blurbArray[$keys[1]];
?>
<pre><? print_r($blurbArray);?></pre>
$('newTitle').value = "<?=addslashes($row['title'])?>";
$('newNewsID').value = "<?=$_GET['newsId']?>";
blurb = FCKeditorAPI.GetInstance('blurb');
blurb.SetHTML("<?=addslashes($blurb)?>");
$('newLink').value = "http://newsrelease.uwaterloo.ca/news.php?id=<?=$_GET['newsId']?>";
<? endif;
} ?> news.php:
<? $stickies = dbQuery(NEWS, 'SELECT id, title FROM newsrelease WHERE onhomepage = 1 and issticky = 0 ORDER BY id DESC LIMIT 30');
?>
<label for="chooseNews">News Release</label>
<select name="chooseNews" id="chooseNews" onchange="loadNewsRelease()">
<option value="" selected="true"></option>
<option value="0">New item</option>
<? while ($sticky = mysql_fetch_array($stickies)) {
echo '<option value="'.$sticky['id'].'" name="'.$sticky['title'].'">'.substr($sticky['title'], 0, 75).(strlen($sticky['title']) > 75 ? '...' : '').'</option>';
}
?>
I've been trying to fix this for a while now, and I think it might be my newbie status with javascript that's preventing me from getting any farther than figuring out the whitespace issue.
Any help you could offer me would be fantastic!
Thanks!
P.S. some of the code tags aren't working...let me know if you know how to fix that and I'll fix em :)