AngularJS-JSON和Coldfusion请求中的特殊字符 [英] AngularJS - Special Characters in JSON and Coldfusion Request

查看:81
本文介绍了AngularJS-JSON和Coldfusion请求中的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JSON字符串在数据库中进行INSERT。我正在使用AngularJS和Coldfusion。

I'm trying to use a JSON string for doing an INSERT in a database . I'm using AngularJS and Coldfusion for doing that.

多亏了我检索数据的表单,我在服务(控制器)中创建了一个对象,并感谢工厂做一个$ http.post。我的问题与发送给它的字符串有关:该字符串包含特殊字符(例如&,而且我不知道如何处理此类问题。)

Thanks to a form I retrieve data, I create an object in the service (controller) and thanks to a factory I do an $http.post. My problem concerns the string sent to it: the string contains special chars (for instance "&" and I don't know how to treat this kind of issue.

以下是发送的字符串的示例:

Here an example of the string sent:

jsStruct={"LASTNAME":"Nämé","FIRSTN%a£öME":"TestFirstName","PHONENUMBER":48484488,"EMAIL":"tes.test@test.test","COMPANY":"Test & Comp"}

我的控制器:

My controller:

app.controller('ctrlAddContacts', function ($scope, ContactService){

    // WHEN SUBMITTING THE FORM -> SEND THE DATA STRING 
    $scope.submitForm = function(contact){
        if($scope.ContactForm.$valid){

            // CALL THE FACTORY -> SEND THE DATA STRING 
            ContactService.addNewPerson(contact).success(function(Person){
                $scope.ContactForm.$setPristine();
                $scope.contact= Person;     

            });     
        }
    }
});

我的工厂:

My Factory:

app.factory('ContactService', function($http){

    var factory={};

    factory.addNewPerson=function(objContact){

        return $http.post('http://myapp/contacts.cfc?method=addNewPerson&jsStruct=' + JSON.stringify(objContact))
    };  

    return factory;

})

在我的Coldfusion组件 contacts.cfc中:

In my Coldfusion component "contacts.cfc":

    <cffunction name="addNewPerson" access="remote" returnformat="JSON" output="no">    
        <cfargument name="jsStruct" type="string" required="true">
        <cfset var cfStruct=DeserializeJSON(jsStruct)>

        ..................

    </cffunction>   

我在服务器上收到此错误,因为在我的字符串中有 COMPANY:测试与比较

I obtain this error on the server because in my string there is "COMPANY":"Test & Comp":

JSON parsing failure: Unexpected end of JSON string 

请帮助我解决此问题,并防止Coldfusion和Oracle使用&,#,',和其他人?

Could you please help me to solve this problem and prevent special characters used by Coldfusion and Oracle as &, #, ', " and others?

预先谢谢您。

推荐答案

事实上,我们要求DBA更改DSN以使用其他驱动程序,并且问题已解决

In fact we asked to the DBA to change the DSN to use different driver and the problem has been solved

这篇关于AngularJS-JSON和Coldfusion请求中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆