Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 服务间通信导致前端错误_Backbone.js_Netsuite_Suitecommerce - Fatal编程技术网

Backbone.js 服务间通信导致前端错误

Backbone.js 服务间通信导致前端错误,backbone.js,netsuite,suitecommerce,Backbone.js,Netsuite,Suitecommerce,登录时,通过serviceAccount.Login.service.ss发出AJAX请求。在这个服务中,我也调用我自己的服务WebStore.service.ss——这就是我所指的服务间通信 奇怪的是,这种服务间通信在后端工作,但前端抱怨出现以下错误: 未捕获的SyntaxError:JSON中位置0处的意外标记

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

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

未捕获的SyntaxError:JSON中位置0处的意外标记<

错误屏幕截图:


原始AJAX/XHR请求的响应是HTML(这就是为什么上面的错误抱怨
您的帐户。Login.Service.ss仅用html响应,因为NetSuite试图告诉您一个错误。通常它也会发送JSON。您在代码中注释
//在
控制台.log()之后不会发生任何错误。
调用,但这可能是导致问题的原因。您试图从服务器端服务登录到控制台,因此无法工作。请改用nlapiLogExecution()。

这看起来不像主干代码?处理请求的前端代码在哪里?
// 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);
    }
}
function service(request, response) 
{
    var Application = require('Application');

    try {

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

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