Brendan Ong
Brendan Ong

Reputation: 1

ReferenceError: onclick function is not defined

I've gotten a "ReferenceError: function is not defined on the saveRoute function". Everything seems right to me but i could not figure out the problem.

Here is the related codes.

<script type="text/javascript">

var array = routeobj;
function saveRoute(){   
var json = JSON.stringify(array)
$.ajax({
    url : "http://192.168.1.9:11123/runornot/drawtrack",
    type: "POST",
    dataType:'json'
   data : {json:json}
       {"routeJson": json },
       console.log("hellohelloworldolr");
    success: function(data, textStatus, jqXHR)
    { //data - response from server
        console.log("checkin success"); },
    error: function (jqXHR, textStatus, errorThrown)
    {
    }});}
</script>    

and in the html

 <a href="#" onClick="saveRoute();" id="savebtn" class="ui-btn ui-corner-all ui-btn-a">Save</a>    

Upvotes: 0

Views: 192

Answers (1)

JDB
JDB

Reputation: 25810

<script type="text/javascript">

var array = routeobj;
function saveRoute(){   
var json = JSON.stringify(array) // <--- best practice would require a semicolon here
$.ajax({
    url : "http://192.168.1.9:11123/runornot/drawtrack",
    type: "POST",
    dataType:'json' // <--- missing a comma

    // the structure doesn't make any sense starting here...
    data : {json:json} // <--- should be a comma here?

    // missing property name?
       {"routeJson": json },

    // is this supposed to be the body of a function?
       console.log("hellohelloworldolr");

    // things start making sense again here...
    success: function(data, textStatus, jqXHR)
    { //data - response from server
        console.log("checkin success"); },
    error: function (jqXHR, textStatus, errorThrown)
    {
    }});}
</script>  

Upvotes: 2

Related Questions