/    Sign up×
Community /Pin to ProfileBookmark

Content Types

So probably not the right forum, but couldn’t think where this should go.

Here’s my script:

[code=php]
<?php
class jsVar{
var $varName;
var $varValue;
var $error;
function jsVar($myarray){
if(count($myarray) == 2 && !is_null($myarray[‘varname’]) && !is_null($myarray[‘varvalue’])){
//only do this for proper arrays
$this->varName=$myarray[‘varname’];
$this->varValue=$myarray[‘varvalue’];
}//if
else{
$this->error=”Invalid column count or array keys found.”;
}
}
function errorCheck(){
return isset($this->error);
}
function showVals(){
if(!$this->errorCheck()){
echo “var “.$this->varName.” = “”.nl2br(stripslashes($this->varValue)).””;<br />n”;
}
}
}
if(isset($_GET[‘dojs’])){
//header(“content-type:text/js”);
//$conn = mysql_connect(connect_data) or die(mysql_error());
$conn = mysql_connect(/*you can’t see me*/) or die(mysql_error());
$sel_db = mysql_select_db(“content”) or die(mysql_error());
$sql = “SELECT varname, varvalue FROM vphodata”;
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$bob = new jsVar($row);
if(!$bob->errorCheck()){
$bob->showVals();
}
}
}
?>
[/code]

I commented out the header line. I think it makes sense to set different content-types based on the file type i’m getting back. although right now it’s just JS, i might send back other types at some point. Does anyone have a list of possible content types for the header function? mine doesn’t work, obviously.

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 03.2006 — Bokeh posted a function here relating file suffix to mime type: http://www.webdeveloper.com/forum/showpost.php?p=520160&postcount=3
Copy linkTweet thisAlerts:
@chazzyauthorMar 03.2006 — so that doesn't have javascript, and i know that JS has its own content type. any clue? oh bokeh....
Copy linkTweet thisAlerts:
@NogDogMar 03.2006 — Some googling suggests the two most popular options are "text/javascript" and "application/x-javascript", and that "text/javascript" is somewhat more widely supported.
Copy linkTweet thisAlerts:
@chazzyauthorMar 03.2006 — !

I think I need to read my code better.

Thanks.
Copy linkTweet thisAlerts:
@bokehMar 03.2006 — Some googling suggests the two most popular options are "text/javascript" and "application/x-javascript", and that "text/javascript" is somewhat more widely supported.[/QUOTE]I don't know about better supported, maybe that refers to browsers like Netscape 3 and 4 that couldn't read modern standards complient Javascript anyway. It seems a lot of the documentation posted on the web is eons old. I answered a thread yesterday (now it looks incorrectly) saying that was the wrong header. Personally I have always used [I]text/javascript[/I] in the document inside the <script> element and [I]Content-Type: application/x-javascript[/I] in the headers. Don't ask why. Force of habit I guess.

Apache (2.0.55) sends [I]Content-Type: application/x-javascript[/I] for files with the [I].js[/I] extension.
Copy linkTweet thisAlerts:
@bokehMar 03.2006 — According to IANA, the body that maintains the list of current media types, [I]text/javascript[/I] is obsolete.

7. JavaScript Media Types

7.1 text/javascript (obsolete)

Type name: text

Subtype name: javascript

Required parameters: none

Optional parameters: charset, see section 4.1.

Encoding considerations:

The same as the considerations in section 3.1 of [RFC3023].

Security considerations: See section 5.

Interoperability considerations:

None except as noted in other sections of this document.

Published specification: [JS15]

Applications which use this media type:

Script interpreters as discussed in this document.

Additional information:

Magic number(s): n/a
File extension(s): .js
Macintosh File Type Code(s): TEXT


Person & email address to contact for further information:

See Author's Address section.

Intended usage: OBSOLETE

Restrictions on usage: n/a

Author: See Author's Address section.

Change controller: The IESG.[/QUOTE]
Copy linkTweet thisAlerts:
@chazzyauthorMar 03.2006 — mmmm obsolete...

dreamweaver only recognizes text types for some reason (when using the script tag). maybe that's how it's supposed to be?
Copy linkTweet thisAlerts:
@bokehMar 03.2006 — The following validate ok ([URL=http://validator.w3.org/]W3C[/URL]) as does [I]text/javascript[/I][code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="application/x-javascript"></script>
<style type="text/css"></style>
<title></title>
</head>

<body>
<p>...</p>
</body>

</html>[/code]
[code=html]<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="application/x-javascript"></script>
<style type="text/css"></style>
<title></title>
</head>

<body>
<p>...</p>
</body>

</html>[/code]
Copy linkTweet thisAlerts:
@chazzyauthorMar 03.2006 — Figured it would.
Copy linkTweet thisAlerts:
@bokehMar 06.2006 — Only thing is... I.E. doesn't recognise:[code=html]<script type="application/x-javascript"></script>[/code] Bah humbug!
Copy linkTweet thisAlerts:
@chazzyauthorMar 06.2006 — Only thing is... I.E. doesn't recognise:[code=html]<script type="application/x-javascript"></script>[/code] Bah humbug![/QUOTE]

A friend of mine asked me to help him put together a web site for reviewing his head shots for clients (he's a photographer). He described how he wanted the site to look so I put it together for him. He uses FF, I use FF, lots of people are using FF. Then he saw it in IE and said "hey how come it doesn't look right". I then proceeded to list the 7 (i think) reasons why it failed to render right in IE. He frowned and said "you really hate IE don't you?".

The moral of the story:

I don't care about IE.

Actually, what you noted isn't unique to javascript. Anything that can be both text/language and application/language fails to work properly in IE - IE is only a text parser. application/xml and application/xhtml (I forget the 2nd header) when viewed directly, IE will ask you to download it.
Copy linkTweet thisAlerts:
@bokehMar 06.2006 — I.E. doesn't have any trouble with this: [I]application/x-javascript[/I] when it is sent in the headers to identify a Javascript file, but does when embeded in the document. [I]application/xhtml+xml[/I] on the other hand makes it pop up a download dialog box, so obviously it sort of knows some [I]application[/I] stuff but not others.
×

Success!

Help @chazzy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...