GVJ
GVJ

Reputation: 67

Getting a Javascript error that property is not a function

I am struggling to solve this issue. Please look into my code below.

function GenericFormHandler(templateId, webService) {
   this.templateId = templateId;
   this.webService = webService;
}

GenericFormHandler.prototype.process = function(form, success, failure) {
    var request= form.serializeArray(); 
    this.webService(request,
        function(data) {
            success(data);
        },
        function(status) {
            failure(status);
        });
};

I am getting error at this.webService. I am running below function with

 function createAccount() {
                var form = $("#login");
                $(form).validationEngine();
                if (!$(form).validationEngine('validate'))
                {
                    return false;
                }

                var handler = new GenericFormHandler('#template','$.ws.userSignUpRequest');
                handler.process(form, function() {
                    window.location.href = "home.html";
                }, function(error) {

                });
            }
            ;

I am accessing webService property in method process but it giving me error as property of an object is not a function. How to solve this error?

Upvotes: 1

Views: 80

Answers (2)

Jamiec
Jamiec

Reputation: 136104

In your code this.webService is set to a string. A string is not a method which can be called

this.webService(request, ... // you passed the string '$.ws.userSignUpRequest' to this

if $.ws.userSignUpRequest is actually a reference to the webservice (as I suspect it is) then you should pass it directly (without quotes) to the constructor of GenericFormHandler

var handler = new GenericFormHandler('#template',$.ws.userSignUpRequest);

Upvotes: 1

Sarath
Sarath

Reputation: 9156

$.ws.userSignUpRequest is this the reference of the function , then pass it with out the string

var handler = new GenericFormHandler('#template', $.ws.userSignUpRequest);

Upvotes: 1

Related Questions