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.

             <mimeMap fileExtension=".json" mimeType="application/json" />


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

        <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" />

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

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

onsdag den 25. februar 2015

Searching for DOM elements

From the site 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 page server method (webservice) - part 2

Simple JavaScript callback to 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)

Another example with javascript calling server with PageMethod for data:

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"/>

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

        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...

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

fredag den 20. februar 2015

Simple JavaScript callback to page server method

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

Fra undervisningen:
Eksempel med hentning af data ved  javascript der kalder PageMethod for data: materiale fra tidligere kursus (5 ects) materiale fra tidligere kursus (5 ects)

JavaScript materiale fra tidligere kursus på 12 lektioner

Tutorials til javascript

Tutorials til javascript

Beginning JavaScript Tutorials

JavaScript Tutorial

JavaScript Kit Advanced JavaScript Tutorials

JavaScript - MDC

JavaScript Kit- JavaScript Reference

JavaScript Core Guide 1.5

JavaScript FAQ

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ø