oentoro
oentoro

Reputation: 750

Uncaught ReferenceError: connect is not defined

I'm using phonegap to develop a mobile application. But, when I try to send data using JSon, I got this error in Android Logcat:

file:///android_asset/www/index.html: Line 31 : Uncaught ReferenceError: connect is not defined

I think I already defined it, here is My index.html code:

<html>
  <head>
    <title>Acceleration Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
    <script charset="utf&minus;8" type="text/javascript">
    function connect(e)
    {
        var term= {button:e};
        $.ajax({
            url:'http://192.168.137.1/server/',
            type:'POST',
            data:term,
            dataType:'json',
            error:function(jqXHR,text_status,strError){
                alert(“no connection”);},
                timeout:60000,
                success:function(data){
                $("#result").html("");
                for(var i in data){
                    $("#result").append("<li>"+data[i]+"</li>");
                }
            }
        });
    }
</script>
  </head>
  <body>
    <center><b>Bikes or Cars</b></center>
    <center><input onclick="connect(this.value)" type="button" value="cars" /></center>
    <center><input onclick="connect(this.value)" type="button" value="bikes" /></center>
    <center><b>Result</b></center>
    <ul id="result"></ul>
  </body>
</html>

Upvotes: 1

Views: 7756

Answers (3)

oentoro
oentoro

Reputation: 750

Add this to header:

<script type="text/javascript" charset="utf-8" src="jquery.mobile/jquery-1.7.2.min"></script>

The problem is $.ajax is defined in jquery.js

Upvotes: 1

fastr.de
fastr.de

Reputation: 1523

First, you have some typos

<script charset="utf&minus;8" type="text/javascript">
...
alert(“no connection”);},

Second, when you get an error like this, but you already declared a function with that name you have possibly an error while the page (and the javascript) is loading. Try to open the page in Chrome with enabled javascript-console (ctrl-alt-J) and look for errors in it.

lg

fastrde

Upvotes: 0

jonas
jonas

Reputation: 935

You have wrong quotes in your alert in the error callback:

alert(“no connection”);

try

alert("no connection");

Upvotes: 0

Related Questions