0

I'm getting an error of "buildXML is not defined" when I run this code:

var c = {

  updateConsumer:function (cid,aid,sid,survey){
    var surveyXML = buildSurveyXML(survey);
  },

  buildSurveyXML: function(survey) { 
    var surveyResults = survey.split("|");
    var surveyXML = '';

    for (var i=0;i<surveyResults.length;i++){
       ...
    }

    return surveyXML;
  }
}

And the html that includes this JS and calls the updateConsumer function:

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <title>Web Service Test</title>
        <meta charset="utf-8">
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
        <script type="text/javascript" src="../../shared/js/consumerSoap.js"></script>
    </head>

    <body>
        <script type="text/javascript">
             $(document).ready(function() {
              c.insertConsumer("First","Last","55555","[email protected]","76:1139");
             });
        </script>
    </body>
</html>
1
  • In c you've defined updateConsumer and buildSurveyXML, but you call insertConsumer in your script block. From this, it looks like buildXML is never called. Is this the right code/markup? Commented Sep 5, 2011 at 15:45

2 Answers 2

2

The problem is that updateConsumer doesn't know anything about buildSurveyXML; that function isn't in the global scope. However, since your function is part of the same object, you can call it using the this keyword.

updateConsumer:function (cid,aid,sid,survey){
    var surveyXML = this.buildSurveyXML(survey);
}
Sign up to request clarification or add additional context in comments.

Comments

0

Use var surveyXML = c.buildSurveyXML(survey);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.