Javascript& Chrome调试器:“未捕获的SyntaxError:意外的令牌}”

时间:2013-06-04 09:04:17

标签: javascript debugging google-chrome

我正在写一个javascript文件。我正在从运行良好的java jersey webservice加载一些数据。然后通过javascript(s.fickSelect() - function)在html表中解析数据。现在我希望字段“id”变为onclickable。单击时,应启动函数“loadRegistrationForm”。

但是当我点击表格的id字段时,Chrome调试器会告诉我: “Uncaught SyntaxError:Unexpected token}”。在Internet Explorer中,它看起来是同一个问题。但对我来说似乎很好,我找不到任何意外的“}”?

有人可以在正确的方向上暗示我出错吗?

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" type="text/css" rel="stylesheet" />
<title>Registrierung für ein Event</title>

<script type="text/javascript"  src="http://code.jquery.com/jquery-2.0.0.js">
</Script>
<script type="text/javascript">

var EventAPI = {
    newRequest: function(type, urlSuffix, data) {
        var request = {
            url: "http://192.168.3.205:8081/MarketingAppServer/rest/MarketingApp/" + urlSuffix,
            type: type,
            data: data ? JSON.stringify(data) : null,
            contentType: "application/json",
            dataType: "json",
        }
        return request;
    },

    addInvitation: function(Customer) {
        var request = EventAPI.newRequest("POST", "createInvitation", Customer);
        $.ajax(request).done(function(response) {
        //alert("Add Invitation Response Message" + response.text);
        });
    },

    getDonwloadLink: function(Customer) {
        var request = EventAPI.newRequest("GET", "getPassFile");
        $.ajax(request).done(function(response) {
        //alert("getDownloadLink Response Message: " + response.text);  
        });
    }
};

callService = function(Uri, successFunction) {
    $.ajax({
        cache: true,
        url: Uri,
        data: "{}",
        type: "GET",
        dataType: "json",
        error: ajaxCallFailed,
        failure: ajaxCallFailed,
        success: successFunction
    });
};

function Customer(Vorname, Name, Email, Firma) {
    this.vorname = Vorname;
    this.name = Name;
    this.emailAdresse = Email;
    this.firma = Firma;
}

function generateInvitation() {
    //generate customer
    var customer = new Customer($("#customer_Vorname").val(), $("#customer_Name").val(), $("#customer_Email").val(), $("#customer_Firma").val());
    EventAPI.addInvitation(customer);
    var displayDownloadLink;
    var fileName = customer.vorname + "_" + customer.name + "_" + customer.emailAdresse + "_" + customer.firma + "_" + "pass.pkpass";

    var xmlhttp;
    xmlhttp = new XMLHttpRequest();
    var url = "http://192.168.3.205:8081/MarketingAppServer/rest/MarketingApp/getPassFile/" + fileName;
    xmlhttp.open('GET', url, true);
    xmlhttp.send(null);
    xmlhttp.onreadystatechange = function() {

        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                var myOutput = "<br>Vielen Dank fuer Ihre Registrierung - Sie koennen ihre Einladung hier herunterladen: <a href='" + xmlhttp.responseText + "'> pass </a>";
                alert(myOutput);
                if (document.getElementById) {
                    document.getElementById("myOutput").clear;
                    document.getElementById("myOutput").innerHTML = myOutput;
                }
            } 
            else {alert("Error ->" + xmlhttp.responseText);}
        }
    };

}

/**
*This function loads a list of available events
*/
function fillSelect() {
    var xmlhttp;
    xmlhttp = new XMLHttpRequest();
    var url = "http://192.168.3.205:8081/MarketingAppServer/rest/MarketingApp/getEventList";
    xmlhttp.open('GET', url, true);
    xmlhttp.send(null);

    xmlhttp.onreadystatechange = function() {

        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            //save returned data to variable
            var data = xmlhttp.responseText;
            alert(data);
            //create result table
            var customerList = '<table border="1">' + "<tr>" + "<th>ID</th>" + "<th>Event</th>" + "<th>Datum</th></tr>";

            //iterate result data & fill table with results
            var myObject = eval('(' + data + ')');
            for (i in myObject) {
                //Problem: Wenn es nur ein Object gibt, dann mdarf nur myObject["id"] aufgerufen werden -- wie kann das vermieden werden?
                var event = new Event(myObject[i]["id"], myObject[i]["eventName"], myObject[i]["eventDate"]);
                alert(event.eventName);
                alert(event.id);
                alert(event.eventDate);
                customerList = customerList.concat(
                "<tr><td id='" + event.id + "' onclick=loadRegistrationForm(" + event + ");return false;'><a href='#'>" + event.id + "</a></td>" + 
                "<td>" + event.eventName + "</td>" + 
                "<td>" + event.eventDate + "</td>" + "</tr>");
                alert(customerList);
            }
            //close data table
            customerList = customerList.concat("</table>");
            //make result table visible
            if (document.getElementById) {
                document.getElementById("myOutput").clear;
                document.getElementById("myOutput").innerHTML = customerList;
            }
        }
    };
}

function Event(id, eventName, eventDate) {
    this.id = id;
    this.eventName = eventName;
    this.eventDate = eventDate;
}

function loadRegistrationForm(Event) {
    alert("test");
//alert(Event.eventName);
}

</script>

</head>
<body>

    <div class="content">
        <img src="res/logo_jpg_klein.jpg" alt="tim_logo" />
        <ul id="Navigation">
            <li><a href="index.html">Wer ist hier </a></li>
            <li><a href="registerforEvent.html">Für Event registrieren </a></li>
        </ul>

        <h1>Hier können Sie sich für ein Event registrieren.</h1>
        <div id="myOutput" class="content"> 

            <form id="formular" name="formular"  action="rest/MarketingApp/createInvitation" method="post" enctype="application/x-www-form-urlencoded" onsubmit="return false;">
            <p>
                <label>Vorname: </label><input type="text" id="customer_Vorname" name="customer_Vorname" />
            </p>
            <p>
                <label>Name: </label> <input type="text" id="customer_Name" name="customer_Name" />
            </p>
            <p>
                <label>Email: </label> <input type="text" id="customer_Email" name="customer_Email" />
            </p>
            <p>
                <label>Firma: </label> <input type="text" id="customer_Firma" name="customer_Firma" />
            </p>
            <br>-------------------------------------------------------------------------<br>
            <p>
                <label>Event: </label> 
                <script type="text/javascript">
                    fillSelect();
                </script>
            </p>
            <select>
                <option value="email">Send pass as Email</option>
            </select>
            <input type="button" value="Fuer Event registrieren" onclick="generateInvitation()" />
            </form>
        </div>

    </div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

您的xmlhttp.responseText很可能包含引号('),它会截断您的警报消息。 检查生成的页面源,看看是否存在问题。 注意:我知道这应该是评论,而不是答案,但我仍然不能评论OP的问题。