【问题标题】:Inter-Service Communication Causes Front-End Error服务间通信导致前端错误
【发布时间】:2017-05-31 01:56:12
【问题描述】:

登录时,通过服务Account.Login.Service.ss 发出AJAX 请求。在这个服务中,我也调用了我自己的服务WebStore.Service.ss——这是我指的服务间通信。

奇怪的是,这种服务间通信在后端工作,但前端抱怨以下错误:

Uncaught SyntaxError: Unexpected token

错误截图:

原始 AJAX/XHR 请求的响应是 HTML(这就是为什么上面的错误抱怨<)。有关 XHR/AJAX 请求的响应,请参见下面的 sn-p。如果我删除服务间通信,那么一切正常。

我的服务 WebStore.Service.ss 响应 JSON 而不是 HTML,所以我认为这不是原因。

知道出了什么问题以及如何使服务间通信正常工作吗?


详情:

下面具体详述服务代码:

Account.Login.Service.ss

// Account.Login.Service.ss
function service (request)
{
    'use strict';

    var Application = require('Application');

    try
    {
        var method = request.getMethod()
        ,   Account = require('Account.Model')
        ,   data = JSON.parse(request.getBody() || '{}');

        // Call service
        // Note no error occurs and everything works.
        try {
            var headers = {"User-Agent-x": "SuiteScript-Call",
                            "Content-Type": "application/json"};
            var response = nlapiRequestURL("http://mywebsite.com/sca-dev-montblanc/services/WebStore.Service.ss?type=is_email_valid&email=foo%40bar.com", null, headers);
            console.log("Making Service call", response);
        } 
        catch (ex) {
            console.log("Error:", e.message); // no error occurs
        }
        // END DEBUG

        switch (method)
        {
            case 'POST':
                //Handles the login and send the response
                Application.sendContent(Account.login(data.email, data.password, data.redirect));
            break;

            default:
                // methodNotAllowedError is defined in ssp library commons.js
                Application.sendError(methodNotAllowedError);
        }
    }
    catch (e)
    {
        Application.sendError(e);
    }
}

WebStore.Service.ss

function service(request, response) 
{
    var Application = require('Application');

    try {

        if (request.getMethod() == 'GET') {

            Application.sendContent( {foo: "bar"} );
        }
    }
    catch (e) {
        Application.sendError(e);
    }
}

来自http://.../Account.Login.Service.ss?n=2&c=4224945&n=2的回复

<!DOCTYPE html>
<html>

<head>
<title>Notice (SuiteScript)</title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
    <script type='text/javascript' src='/ui/jquery/jquery-1.11.3.min.js?NS_VER=2017.1.0&minver=75'></script>
    <script type='text/javascript' src='/ui/jquery/jquery_isolation.js?NS_VER=2017.1.0&minver=75'></script>
    <script type='text/javascript' src='/javascript/NLUtil.jsp?NS_VER=2017.1.0&minver=75&locale=en_AU&JSP_VER=1&locale=en_AU&JSP_VER=1&JSP_VER=1'></script>
    <script type='text/javascript' src='/javascript/NLUtil.js?NS_VER=2017.1.0&minver=75'></script>
    <script type='text/javascript' src='/javascript/NLUIWidgets.jsp?NS_VER=2017.1.0&minver=75&locale=en_AU&JSP_VER=1&locale=en_AU&JSP_VER=1&JSP_VER=1'></script>
    <script type='text/javascript' src='/assets/legacy_widgets/1701411811.js?NS_VER=2017.1.0&minver=75'></script>
    <script type='text/javascript' src='/assets/legacy_apputil/1733410633.js?NS_VER=2017.1.0&minver=75'></script>
    <script type='text/javascript' src='/javascript/NLAppUtil.jsp?NS_VER=2017.1.0&minver=75&locale=en_AU&JSP_VER=1&locale=en_AU&JSP_VER=1&JSP_VER=1'></script>
    <script type='text/javascript' src='/uirefresh/script/global.js__NS_VER=2017.1.0&minver=75&locale=en_AU.nlqs?NS_VER=2017.1.0&minver=75'></script>
<link rel='stylesheet' href='/core/styles/pagestyles.nl'><link rel='stylesheet' type='text/css' href='/uirefresh/css/button.css' />
</head>

<body bgcolor='#FFFFFF' link='#000000' vlink='#000000' alink='#330099' text='#000000' topmargin='0' marginheight='1' onload='page_init()' class='error-page'>
<img src='/images/nav/stretch.gif' width='10'><img class='uir-logo' src='/images/logos/netsuite-reskin.png' border=0 style='margin-right:30px;'><img src='/images/logos/sandbox_logo.gif' height='30' width='125' border=0>
<table border=0 cellPadding=0 cellSpacing=0 width=100%>

<tr><td class='bglt'>
<table border='0' cellspacing='0' cellpadding='5' width='100%'>
<tr><td class='textboldnolink'>Notice (SuiteScript)</td></tr>
<tr><td vAlign='top'>
<table border='0' cellspacing='0' cellpadding='0' width='100%'>
<tr><td class='text'>&nbsp;</td></tr>

<tr><td class=text><img src='/images/5square.gif' width=5 height=5>An unexpected SuiteScript error has occurred</td></tr>

<tr><td class='text'>&nbsp;</td></tr>
<tr><td class='text'>&nbsp;</td></tr>
</table></td></tr></table></td></tr>
<tr><td> <table id='tbl_goback' cellpadding='0' cellspacing='0' border='0' class='uir-button' style='margin-right:6px;cursor:hand;' role='presentation'> <tr id='tr_goback' class='pgBntG pgBntB'> <td id='tdleftcap_goback'><img src='/images/nav/ns_x.gif' class='bntLT' border='0' height='50%' width='3' alt=''/> <img src='/images/nav/ns_x.gif' class='bntLB' border='0' height='50%' width='3' alt=''/> </td> <td id='tdbody_goback' height='20' valign='top' nowrap class='bntBgB'> <input type='button' style='' class='rndbuttoninpt bntBgT' value='Go Back' id='goback' name='goback' onclick="history.back(); return false;" onmousedown="this.setAttribute('_mousedown','T'); setButtonDown(true, false, this);" onmouseup="this.setAttribute('_mousedown','F'); setButtonDown(false, false, this);" onmouseout="if(this.getAttribute('_mousedown')=='T') setButtonDown(false, false, this);" onmouseover="if(this.getAttribute('_mousedown')=='T') setButtonDown(true, false, this);" ></td> <td id='tdrightcap_goback'> <img src='/images/nav/ns_x.gif' height='50%' class='bntRT' border='0' width='3' alt=''> <img src='/images/nav/ns_x.gif' height='50%' class='bntRB' border='0' width='3' alt=''> </td> </tr> </table> </td></tr>
</table>

<script language='JavaScript' type='text/javascript'>
function page_init() {
}
</script>

</body>
</html>

【问题讨论】:

  • 这看起来不像主干代码?处理请求的前端代码在哪里?

标签: backbone.js netsuite suitecommerce


【解决方案1】:

您的 Account.Login.Service.ss 仅使用 html 响应,因为 NetSuite 试图告诉您一个错误。通常它也会发送 JSON。您在 // no error occurs 调用 console.log() 之后在代码中发表评论,但这可能是导致问题的原因。您正在尝试从服务器端服务登录到控制台,所以这不起作用。请改用 nlapiLogExecution()。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 2020-03-06
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 2021-10-17
    相关资源
    最近更新 更多