Joseph Ebey
Joseph Ebey

Reputation: 49

cant keep basic cloud code function to work using parse.com

I am unable to get basic cloud code functions working using Parse.com. I want to keep main.js as clean as possible, and also want to attach functions to HTML buttons and keep that process clean and easy to use. My solution was to only use main.js for cloud code definition, and use another file(app.js) to house my functions that would call the cloud code and house my non cloud code functions. For some reason I get errors when using require, it wont recognize Parse.Cloud.Define, to name a few problems. I have reduced my code down to the simplest function possible and I still cant get it to work. I am getting so frustrated with Parse. I had my code working locally but when I tried converting it to cloud code on Parse I have run into so many problems, can I please get some help to atleast get me through this hurdle. Ill post all of my code below. The error I am getting is that require is causing an error that says require is undefined. Whats even more annoying is that if I look at the logs on Parse.com the function runs and Hello World! is properly logged. This is causing the function to not run correctly in the browser though(this function runs but others ive been testing dont). Can I get any help as to why require is causing errors on such a simple set of code? Thanks in advance

main.js

Parse.initialize("xxxx", "xxxx"); // xxxx is just to hide my ID.
require('cloud/app.js');

Parse.Cloud.define("hello", function(request, response) {
    response.success("Hello world!");
});

app.js

function callHello(){
    Parse.Cloud.run('hello', {}, {
        success: function(result){              
        },
        error: function(error){             
        }
    });
} 

HTML page running the callHello() function

<!doctype html>
<head>
  <meta name="description" content="IT Ticket System">
  <meta name="viewport" content="width=device-width">
  <meta charset="utf-8">
  <title>IT Ticket Request</title>

  <link rel="stylesheet" href="css/reset.css">
  <link rel="stylesheet" href="css/styles.css">
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.4.2.min.js"></script>
  <script type ="text/javascript" src="../cloud/main.js"></script>
  <script type ="text/javascript" src="../cloud/app.js"></script>
</head>
  <body> <br>
    <img src="images/logo.png">
    <div class="inputForm">
      <br><br>
      <h1>Login</h1><br><br>

         <button type="button" onclick="callHello()">test</button> 
    </div>
   </body>
  </html>

Upvotes: 0

Views: 482

Answers (1)

Wain
Wain

Reputation: 119041

The javascript files (main.js) for your cloud code should be uploaded to parse, they live and are executed in the parse container in the cloud.

Your javascript in your web page should be using the Parse JS SDK to call the specified parse cloud function and handle the response. It can't directly import the parse cloud code JS.

So your app.js file looks fine to use directly but your main.js file needs to be uploaded and not included in your web page.

Upvotes: 1

Related Questions