-2

I have created app in script.google.com and defined the function below which is triggered when any cell in the sheet will change.

Now I would like to update that value in mysql database so i need ajax call.

below are the script code which is defined in my google script (script.google.com).

    function onEdit(e) {
      var row_res = e.range.getRow();
      var column = e.range.getColumn();

        $.ajax({      
          url : 'http://dev.digitalvidya.com/assist/sheet/sort',
          type : 'GET',
          data : {
            'row' : row_res 
          },
          dataType:'json',
          success : function(data) {             
            alert('Data: '+data);
          },
          error : function(request,error)
          {
            alert("Request: "+JSON.stringify(request));
          }
        });
    }
tehhowch
  • 9,645
  • 4
  • 24
  • 42
cdo90
  • 11
  • 2
  • What have you tried? Where are you stuck? This isn't a free design-my-database service, but we will help you if you have a problem which is more specific . – danblack Jan 16 '19 at 09:18
  • i would like to use ajax call in script.google.com app. as explain above. above ajax call is not working. – cdo90 Jan 16 '19 at 09:28
  • If it was explained I wouldn't be asking questions. "not working", does it generate an error? Wrong results? Doesn't get called? Sits on couch eating chips? – danblack Jan 16 '19 at 09:34
  • No, i can not get any error because this function is called when spreadsheet cell will update. this code is in https://script.google.com/ – cdo90 Jan 16 '19 at 09:39
  • Welcome to StackOverflow. Please read the help section on [how to ask](https://stackoverflow.com/help/how-to-ask) and then edit your question, as this will help the community better understand your specific issue and provide you with a good answer. – Graham Jan 16 '19 at 09:58
  • 3
    `$.ajax` is not valid [Google Apps Script](https://developers.google.com/apps-script/guides/services/#basic_javascript_features). You probably want to review the limitations on [simple triggers](https://developers.google.com/apps-script/guides/triggers/) and how to make [external requests](https://developers.google.com/apps-script/reference/url-fetch/). – tehhowch Jan 16 '19 at 14:35
  • Also review [jdbc](https://developers.google.com/apps-script/guides/jdbc) – TheMaster Jan 16 '19 at 15:39
  • Thanks for JDBC suggestion. but will not connect with my db. below is the code which i used in script – cdo90 Jan 17 '19 at 08:55
  • var dbUrl = 'jdbc:mysql://sql12.freesqldatabase.com:3306/sql12274518'; var user = 'sql12274518'; var userPwd = '16BKPJCNa7'; var conn = Jdbc.getConnection(dbUrl, user, userPwd); Logger.log("hi_2.1 :"); var stmt = conn.createStatement(); Logger.log("hi_3 :"); var sql = "INSERT INTO test (name, email, msg) VALUES ('cdo_1','cdo@gmail.com','testing')"; var count = stmt.executeUpdate(sql,1); Logger.log("hi :"+count); – cdo90 Jan 17 '19 at 08:55
  • `will not connect` or ``doesn't work `` is not a problem description. Ask a new question with [mcve] – TheMaster Jan 18 '19 at 02:34

1 Answers1

1

$ is a JavaScript identifier usually used as a shorthand for the jQuery object.

On Google Apps Script server side code we can't use something like

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Instead of "ajax", we could use the URL Fetch service for HTTP requests or JDBC service to connect to external databases.

Reference

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Thanks for JDBC suggestion. but will not connect with my db. below is the code which i used in script – cdo90 Jan 17 '19 at 11:50
  • var dbUrl = 'jdbc:mysql://sql12.freesqldatabase.com:3306/sql12274518'; var user = 'sql12274518'; var userPwd = '16BKPJCNa7'; var conn = Jdbc.getConnection(dbUrl, user, userPwd); Logger.log("hi_2.1 :"); var stmt = conn.createStatement(); Logger.log("hi_3 :"); var sql = "INSERT INTO test (name, email, msg) VALUES ('cdo_1','cdo@gmail.com','testing')"; var count = stmt.executeUpdate(sql,1); Logger.log("hi :"+count); – cdo90 Jan 17 '19 at 11:50
  • @cdo90 I think that you should post a new question, including a [mcve] and the execution transcript. – Rubén Jan 17 '19 at 16:58