Skip to main content

Getting s.Type.ToUpperCase() is not a function when calling WCF service with $ajax

I'm using WCF and I am getting this error. If I use jQuery1.14.1 I get

Type error: s.type.ToUpperCase is not a function

type = s.type.ToUpperCase();

If I use jQuery 1.12.1 locally the service gets called corrctly. However, if I try it on the server, 1.14.1 get the error above, but 1.12 i get this one:

Type error: l.type.ToUpperCase() is not a function ..+&&n.event.trigger("ajaxStart"),l.type=l.type.ToUpperCase(), l,hasContent=!Kb.tes....

Relevant code:

var Type = "POST";
var DataType = "jsonp";
var ProcessData = true;
var ContentType = "application/json; charset=utf-8";

var params = {
    user: $("#userid_hidden").val().toString(),
    permission: $("#permission_id_" + i).val().toString(),
    enabled: true,
    note: $("#permission_note_" + i).val(),
    write: $("#permission_write_" + i).is(":checked")
}
SetPermission(params);

function SetPermission(params) {
    //alert('setting permission');
    if (params.enabled)
        CallService('wsEnablePermissionJSON', params);
    else
        CallService('wsDisablePermissionJSON', params);
}

function CallService(wsName, params) { //Generic function to call WCF  Service

    alert('calling service');
    $.ajax({
        type: Type, //GET or POST or PUT or DELETE verb
        url: Url + wsName, // Location of the service
        data: JSON.stringify(params),
        /*data: JSON.stringify(params),                          //Data sent to server*/
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function(msg) { //On Successful service call
            ServiceSucceeded(msg, wsName);
        },
        error: ServiceFailed // When Service call fails
    });
    alert('service called');
}

I can't see the rest of the error because the page is then reloaded, I got those by taking a screenshot.

I don't know how to go about this, I've tried jQuery 2 and I get the first error. I've used the same ajax call with another wcf service and it's currently working fine (the only difference is that the working one uses jQuery 1.12, and that solved it locally, in the server the new one fails.)

Both pages are in the same server.

I've been trying to figure this out for most of the day, but I haven't found anything, at first I thought that using 1.12 would solve it. I googled the error but all the results were for different cases, I didn't see anything for the $ajax call.

Solved

This was happening pecause the name of the variable Type

 var Type = "POST";

I didn't think to change it before, because as I've said before I have another web app very similar, and with exactly the same ajax call working fine, and that code I got from an example somewhere.

Changing it to

 var Requestype = "POST";

took care of the error


I ran into the same error, but for a different reason. I was accidentally passing the value true in the type property, instead of a POST.

If it contains any value other than the accepted verbs. Remember that it defaults to GET, if none provided.

Hope this helps somebody.


Comments

Popular posts from this blog

Could not run elki.sh in mac OSX

In order to use ELKI to do a clustering task, I have downloaded the latest complete release package: elki-0.7.1 The README.PDF says to run elki.sh on OSX. However, after I run the elki.sh with Terminal, it pops the following error: Error: Could not find or load main class de.lmu.ifi.dbs.elki.application.ELKILauncher I am sure I have downloaded the complete packages entirely, but still could not run ELKI successfully. Thanks in advance! Solved I will show below how you can install Elki in macOS, El Capitan Version 10.11.6. Installation of ELKI in macOS brew cask install java git clone https://github.com/elki-project/elki.git cd elki ./gradlew shadowJar ./gradlew build open elki-bundle-0.7.2-SNAPSHOT.jar where you can see the ELKILauncher. Example that ELKI is working just fine Background You don't have to configure any paths, actually. Questions you may want to ask yourself are Did you build the Elki on the command line? Do y...

Can't access property inside object initializer

Consider the following code. List files = new List (); .... while (reader.Read()) { var a = new MyFiles { FileName = reader["Filename"].ToString(), FileLocation = reader["Filelocation"].ToString(), FullPath = FileLocation + @"\" + FileName // Error at this line }; files.Add(a); } The above is a snippet from my method which uses SqlDataReader to fetch data from the database. Everything works fine expect when I try to assign value to FullPath property I get the following error message: An object reference is required for the non-static field, method, or property 'MyFiles.FileLocation' An object reference is required for the non-static field, method, or property 'MyFiles.FileName' I know I can make those properties static or create an instance and access them via e.g. var b = new MyFiles(); b.FileLocation .. But my question is why can't I use FileLocation and FileName as I am in t...