torsdag den 26. marts 2015

Define extra MIME types in web.config to accecpt fx. .json file like .txt file

If you want to have filename as my.json instead if my.txt file - you will have the problem that server don't know how to response for request for my.json as it don't know the type.
You can define the type (MIME)  in the web.config file.

Example for accept .json to be handlet like .txt file.

<configuration>
........................
   <system.webServer>
   .......................
        <staticContent>
             <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
   ........................
   </system.webServer>

........................
</configuration>​

Thank Vigan S for the input.

How to make WCF service available for JavaScript from for foreign server

Normaly you could not make XMLHttpRequest in JavaScript to a service on another server.

If you have access to change the Web.Config on the server you want til make request to, you can set up some extra information for the http header to make request possibly.

Example - part of Web.Config file

<configuration>
......
   <system.webServer>
......  
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*"/>
        <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
        <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
        <add name="Access-Control-Max-Age" value="1728000" />
      </customHeaders>
    </httpProtocol>
......  
   </system.webServer>
......  
</configuration>

You can find more information here:
Description in details:

Thank you Jeppe B for the solution.

søndag den 15. marts 2015

Scale HTML page to fill screen on mobile device

When you watch a HTML page on a mobile device you might want the size til scale to the screensize.
This can be done by placing meta information viewport in html head and set the scale to 1.
For half size set scale to 0.5

<head>
.......
<meta name="viewport" content="width=device-width, initial-scale=1" />
......
</head>

onsdag den 25. februar 2015

Searching for DOM elements


From the site http://javascript.info/tutorial/searching-elements-dom we get this summary
There are 5 main ways of querying DOM:
  1. getElementById
  2. getElementsByTagName
  3. getElementsByName
  4. getElementsByClassName (except IE<9)
  5. querySelector (except IE<8 and IE8 in compat mode)
All of them can search inside any other element. All of them excepts the last one return live collections.


XPath is kind-of supported in most browsers, but very rarely used.

tirsdag den 24. februar 2015

Simple JavaScript callback to asp.net page server method (webservice) - part 2


Simple JavaScript callback to asp.net page server method (webservice)
- easy as client JavaScript method (except call should be asyncrone - se later)
- manage type as JavaScript (don't think of converting to json or xml)

Pp_JavaScriptCodeBehindOgPageMethods.ppt
example: JavaScriptValideringSolution_20140331.zip
Another example with javascript calling server with PageMethod for data:
JavaScriptCallPageWebmethodSolution.zip


If you want to make easy acces to methods on server from javascript in ASP.NET environment, you just can use a ASPX Webform for hosting af service on the page.
You just need to place a ScriptManager to control access in a ASPX form objet - both with runat sever properties. Rest og the file could be pure Html and javascript.
Remember to eable page methods.

<form id="form1" runat="server">
          <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="True"
                    EnablePartialRendering="true" runat="server"/>
 </form>

Place the server method on the codebehind c# file with atribute for method like this
In this example it just call another (wcf soap) service to do the job.
In the ASPX page C# page

        [System.Web.Services.WebMethod]
        public static PostWcfService.PostdistriktDTO[]  GetAllPost(int fromPost, int toPost)
        {
            PostWcfService.PostWcfServiceClient service =
                new PostWcfService.PostWcfServiceClient();
            return service.GetAllePostdistrikterFraTil__PostnrOrder(fromPost, toPost);
        }

In the JavaScript the method is called like this

    PageMethods.GetAllPost(5000, 5200, onSucessGetAllPost, onerrorGetAllPost);

First the parameter to the webmethod followed by at callback method to pass the result and last a callback method i the page method fails.

function onSucessGetAllPost(result)
{
       // result is an Javascript Array object containing Postdistrict objects
       // and is ready to use -  fx running through by for-loop and displayd in UI
}
}
function onerrorGetAllPost(result) {
      // to do for errorhandling
}

Normally you have a problem calling webmethod on another site,
With this solution we solved the problem with the page method. The page method will act like a proxy/broker for the external service.

You can find a soluton with the example here - also getting data with WebClient for JSON, XML, HTML and TEXT...
Week09_SolutionJavaScriptPart02_WithWebClientData_20150224.zip

An a expanded example with som coverting text from WebClient in JSON, XML and HTML to javascript objects.
Week09_SolutionJavaScriptPart03_WithWebClientDataConverted_20150224.zip




fredag den 20. februar 2015

Simple JavaScript callback to asp.net page server method


Simple JavaScript callback to asp.net page server method (webservice)
- easy as client JavaScript method
- manage type as JavaScript (don't think of converting to json or xml)

Pp_JavaScriptCodeBehindOgPageMethods.ppt
Fra undervisningen: JavaScriptValideringSolution_20140331.zip
Eksempel med hentning af data ved  javascript der kalder PageMethod for data:
JavaScriptCallPageWebmethodSolution.zip

Asp.net materiale fra tidligere kursus (5 ects)

Asp.net materiale fra tidligere kursus (5 ects)
Ugeplaner
Eksempler_og_noter
Opgaver

JavaScript materiale fra tidligere kursus på 12 lektioner

Tutorials til javascript


Tutorials til javascript

Beginning JavaScript Tutorials
http://www.pageresource.com/jscript/index.html

JavaScript Tutorial
http://www.w3schools.com/js/default.asp

JavaScript Kit Advanced JavaScript Tutorials
http://www.javascriptkit.com/javatutors/

JavaScript - MDC
http://developer.mozilla.org/en/docs/JavaScript


References
JavaScript Kit- JavaScript Reference
http://www.javascriptkit.com/jsref/index.shtml

JavaScript Core Guide 1.5
http://www.webreference.com/javascript/reference/core_ref/

JavaScript FAQ
http://www.javascripter.net/faq/index.htm


onsdag den 11. februar 2015

Start på web blog

Blog oprettet for brug på datamatikeruddannelsen ved EAL inden for fagområdet udvikling til web udvikling

Det er tanken at studerende er med til at bruge denne blog, herunder som forfattere (henvend dig til Bjørk Boye Busch med en gmail adresse for rettighed som forfatter).

Du finder også materiale på min egen blog http://bjørks.blogspot.dk/