引用错误: 未定义 onclick 函数

ReferenceError: onclick function is not defined

本文关键字:onclick 函数 未定义 错误 引用      更新时间:2023-09-26

我得到了一个"ReferenceError:函数未在saveRoute函数上定义"。对我来说一切似乎都是对的,但我无法弄清楚问题所在。

以下是相关代码。

<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>    

并在 HTML 中

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