0

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>    
6
  • 3
    if that is your code exactly as you have it, there are some syntax errors. These might be causing your method to never be properly defined. Commented Jan 27, 2015 at 19:54
  • Also you need to preventDefault() Commented Jan 27, 2015 at 19:56
  • @lemieuxster there are syntax errors? Can i know about these syntax errors. i really could not identify the errors. Commented Jan 27, 2015 at 20:02
  • 1
    @BrendanOng yeah, big ones... dataType: 'json' needs a comma after it, and then the three lines immediately afterword that are supposed to be the value for data: are seriously weird. What are you trying to do there? Commented Jan 27, 2015 at 20:06
  • 4
    Debugging is a fundamental skill of a software engineer. I recommend to learn how to debug JavaScript so that you can solve such problems yourself. Then of course you have to learn the basic JavaScript syntax as well. Commented Jan 27, 2015 at 20:30

1 Answer 1

2
<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>  
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.