Click here to Skip to main content
15,887,477 members
Home / Discussions / JavaScript
   

JavaScript

 
Questionjavascript certification study pal Pin
Member 1117229022-Oct-14 3:13
Member 1117229022-Oct-14 3:13 
QuestionJQGrid and MIT license Pin
Sibeesh KV9-Oct-14 19:20
professionalSibeesh KV9-Oct-14 19:20 
AnswerRe: JQGrid and MIT license Pin
Richard Deeming9-Oct-14 22:52
mveRichard Deeming9-Oct-14 22:52 
GeneralRe: JQGrid and MIT license Pin
Sibeesh KV12-Oct-14 23:40
professionalSibeesh KV12-Oct-14 23:40 
AnswerRe: JQGrid and MIT license Pin
Sunasara Imdadhusen12-Oct-14 23:32
professionalSunasara Imdadhusen12-Oct-14 23:32 
GeneralRe: JQGrid and MIT license Pin
Sibeesh KV12-Oct-14 23:40
professionalSibeesh KV12-Oct-14 23:40 
Questiondropdown edit type selection to read mode for few records. Pin
parkway9-Oct-14 7:06
parkway9-Oct-14 7:06 
QuestionCross domain SOAP call (with XmlHttpRequest) to a webservice with windows authentication Pin
michielke8-Oct-14 22:12
michielke8-Oct-14 22:12 
We have a .Net webservice which runs on one server and a web application (javascript) running on another. The webservice needs to have Windows Authentication.

We keep getting the error 401 Unauthorized on the CORS Preflight call, which preceeds the cross domain webservice call. If we move the webservice on the same machine as the application, the calls run perfectly.

Spent four days now to get it working, hopefully someone here can point me in the right direction...

P.S.: added a JSFiddle which demonstrates the problem. http://jsfiddle.net/mr9Lpbc1/34/[^]

Here is the web.config we use for the webservice

XML
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <appSettings />
  <connectionStrings />
  <system.web>
    <compilation debug="true" />
    <authentication mode="Windows" />
    <customErrors mode="Off" />
    <webServices>
      <protocols>
        <add name="HttpSoap" />
        <add name="HttpGet" />
        <add name="HttpPost" />
      </protocols>
    </webServices>
	<httpRuntime maxUrlLength="9999" relaxedUrlToFileSystemMapping="true" maxQueryStringLength="2097151" requestValidationMode="2.0"/>
    <pages validateRequest="false" />
  </system.web>
  <system.webServer>
    <defaultDocument>
      <files>
        <remove value="default.aspx" />
        <remove value="Default.asp" />
        <remove value="index.html" />
        <remove value="iisstart.htm" />
        <remove value="index.htm" />
        <remove value="Default.htm" />
        <add value="webservice.asmx" />
      </files>
    </defaultDocument>
        <httpProtocol>
            <customHeaders>
                <add name="Access-Control-Allow-Origin" value="http://domain.nl" />
                <add name="Access-Control-Allow-Credentials" value="true" />
                <add name="Access-Control-Allow-Headers" value="SOAPAction, Content-Type,Authorization" />
                <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
            </customHeaders>
        </httpProtocol>
	  <security>
		  <requestFiltering>
			  <requestLimits maxUrl="10999" maxQueryString="9999" />
		  </requestFiltering>
	  </security>
  </system.webServer>
</configuration>


Here is the peace of javascript we are using

JavaScript
SOAPClientParameters = (function () {
    function SOAPClientParameters() {
        var self = this;

        self.list = new Array();
    }

    SOAPClientParameters.prototype.add = function (name, value) {
        var self = this;

        self.list[name] = value;
        return self;
    };

    SOAPClientParameters.prototype._serialize = function (o) {
        var s = "";
        switch (typeof (o)) {
            case "string":
                s += o; //real code is a little different but includes >
            case "number":
            case "boolean":
                s += o.toString(); break;
            case "object":
                // Date
                if (testNull(o)) { s += ""; }
                else if (typeof o === 'Date') {
                    dateToSqlString(o); // custom external function to create date to string suitable for MSSQL
                }
                else if (typeof o === 'Array') {
                    for (var p in o) {
                        if (!isNaN(p))   // linear array
                        {
                            (/function\s+(\w*)\s*\(/ig).exec(o[p].constructor.toString());
                            var type = RegExp.$1;
                            switch (type) {
                                case "":
                                    type = typeof (o[p]);
                                case "String":
                                    type = "string"; break;
                                case "Number":
                                    type = "int"; break;
                                case "Boolean":
                                    type = "bool"; break;
                                case "Date":
                                    type = "DateTime"; break;
                            }
                            s += "<" + type + ">" + SOAPClientParameters._serialize(o[p]) + "</" + type + ">"
                        }
                        else    // associative array
                            s += "<" + p + ">" + SOAPClientParameters._serialize(o[p]) + "</" + p + ">"
                    }
                }
                else
                    for (var p in o)
                        s += "<" + p + ">" + SOAPClientParameters._serialize(o[p]) + "</" + p + ">";
                break;
            default:
                throw new Error(500, "SOAPClientParameters: type '" + typeof (o) + "' is not supported");
        }
        return s;
    }

    SOAPClientParameters.prototype.toXml = function () {
        var self = this;

        var xml = "";
        for (var p in self.list) {
            if (typeof self.list[p] !== 'function') {
                xml += "<" + p + ">" + self._serialize(self.list[p]) + "</" + p + ">";
            }
        }
        return xml;
    }

    return SOAPClientParameters;
}());


SOAPClient = (function () {
    function SOAPClient(url, async) {
        var self = this;

        self.xmlHttp = null;

        if (window.XMLHttpRequest) {
            self.xmlHttp = new XMLHttpRequest();
            // patch for Moz (some versions)
            if (self.xmlHttp.readyState == null) {
                self.xmlHttp.readyState = 1;
                self.xmlHttp.addEventListener("load",
                                    function () {
                                        self.xmlHttp.readyState = 4;
                                        if (typeof self.xmlHttp.onreadystatechange == "function")
                                            self.xmlHttp.onreadystatechange();
                                    },
                                    false);
            }
            //req.withCredentials = true; // tried this, but didn't work
        } else {
            throw 'This browser is not supported!';
        }

        self.xmlHttp.async = async;
        if (self.xmlHttp !== null) {
            self.xmlHttp.open("POST", url, self.xmlHttp.async);
            self.xmlHttp.url = url;
            self.xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            self.xmlHttp.onerror = function () { // handle eg. 40x errors
                if (self.xmlHttp.async) {
                    // resend it synchronous and catch the exception
                    var errorClient = new SOAPClient(self.xmlHttp.url, false);
                    var exception = errorClient.invoke(self.xmlHttp.func, self.xmlHttp.parameters, function () { }, function () { });
                    self.xmlHttp.errorCallback(isnull(exception.message, 'Unknown error...'));
                }
            }

            self.xmlHttp.onload = function () { // handle eg. 50x errors
                if ((self.xmlHttp.readyState === 4) && (self.xmlHttp.status !== 200)) {
                    self.xmlHttp.errorCallback(self.xmlHttp.statusText);
                }
            }
        }
    }

    SOAPClient.prototype.result = function (data) {
        return data;
    };

    SOAPClient.prototype.invoke = function (method, parameters, successCallback, errorCallback) {
        var self = this;

        var ns = 'http://domain.com/';
        var sr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
            "<soap:Envelope " +
            "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
            "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
            "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
            "<soap:Body>" +
            "<" + method + " xmlns=\"" + ns + "\">" +
            parameters.toXml() +
            "</" + method + "></soap:Body></soap:Envelope>";

        var soapaction = ((ns.lastIndexOf("/") != ns.length - 1) ? ns + "/" : ns) + method;

        self.xmlHttp.function = method;
        self.xmlHttp.parameters = parameters;
        self.xmlHttp.errorCallback = errorCallback;

        self.xmlHttp.setRequestHeader("SOAPAction", soapaction);

        if (self.xmlHttp.async) {
            self.xmlHttp.onreadystatechange = function () {
                if ((self.xmlHttp.readyState == 4) && (self.xmlHttp.status === 200)) {
                    self.onSuccess();
                }
            }
        }

        try {
            self.xmlHttp.send(sr);
            if (!self.xmlHttp.async) {
                self.onSuccess();
            }
        } catch (ex) {
            return ex;
        }
    }

    SOAPClient.prototype.onSuccess = function () {
        var self = this;

        if ((self.xmlHttp.readyState == 4) && (self.xmlHttp.status === 200)) {
            var o = null;
            var responseText = self.xmlHttp.response;

            // do the success callback here
        }
    }

    return SOAPClient;
}());


modified 9-Oct-14 8:03am.

Questionhow to display timer starting from 0 minutes and increment further Pin
Member 105573645-Oct-14 1:08
Member 105573645-Oct-14 1:08 
SuggestionRe: how to display timer starting from 0 minutes and increment further Pin
Kornfeld Eliyahu Peter5-Oct-14 1:15
professionalKornfeld Eliyahu Peter5-Oct-14 1:15 
QuestionJavascript and arrays Pin
Member 1111635128-Sep-14 16:32
Member 1111635128-Sep-14 16:32 
SuggestionRe: Javascript and arrays Pin
Kornfeld Eliyahu Peter28-Sep-14 20:58
professionalKornfeld Eliyahu Peter28-Sep-14 20:58 
QuestionJavascript and arrays Pin
Member 1111635128-Sep-14 16:30
Member 1111635128-Sep-14 16:30 
AnswerRe: Javascript and arrays Pin
Kornfeld Eliyahu Peter28-Sep-14 21:00
professionalKornfeld Eliyahu Peter28-Sep-14 21:00 
AnswerRe: Javascript and arrays Pin
Richard MacCutchan28-Sep-14 22:07
mveRichard MacCutchan28-Sep-14 22:07 
GeneralRe: Javascript and arrays Pin
Sunasara Imdadhusen12-Oct-14 23:34
professionalSunasara Imdadhusen12-Oct-14 23:34 
Questionckeditor, custom dialog, element ID's are different from Firefox and IE Pin
jkirkerx24-Sep-14 10:28
professionaljkirkerx24-Sep-14 10:28 
QuestionJQuery,JavaScript,Angular JS Pin
Sibeesh KV23-Sep-14 19:05
professionalSibeesh KV23-Sep-14 19:05 
AnswerRe: JQuery,JavaScript,Angular JS Pin
Vindhyachal_Kumar24-Sep-14 1:23
professionalVindhyachal_Kumar24-Sep-14 1:23 
GeneralRe: JQuery,JavaScript,Angular JS Pin
Sibeesh KV24-Sep-14 1:40
professionalSibeesh KV24-Sep-14 1:40 
AnswerRe: JQuery,JavaScript,Angular JS Pin
thatraja24-Sep-14 2:40
professionalthatraja24-Sep-14 2:40 
GeneralRe: JQuery,JavaScript,Angular JS Pin
ZurdoDev24-Sep-14 3:15
professionalZurdoDev24-Sep-14 3:15 
GeneralRe: JQuery,JavaScript,Angular JS Pin
Sunasara Imdadhusen12-Oct-14 23:35
professionalSunasara Imdadhusen12-Oct-14 23:35 
GeneralRe: JQuery,JavaScript,Angular JS Pin
Sibeesh KV24-Sep-14 3:28
professionalSibeesh KV24-Sep-14 3:28 
GeneralRe: JQuery,JavaScript,Angular JS Pin
Leng Vang13-Oct-14 7:53
Leng Vang13-Oct-14 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.