Angular Js On表单提交发送json字符串到服务器

时间:2016-06-25 15:10:39

标签: javascript php jquery angularjs json

我创建了一个工厂来管理json数据

angular
.module("autoQuote")
.controller(dtoController)
.factory(prepareDtoFactory);

function dtoController(prepareDtoFactory){
     prepareDtoFactory.rc1Step1DTO(); //call function from your service, and do something with it
}

dtoController.$inject = ['prepareDtoFactory'];

function prepareDtoFactory(){

    var prepareAutoQuoteDTO = {
        postAutoQuoteObj         : $.getAutoQuoteObject(),  
        initializeDriverObj: function(){
            var driverLocObj           = new Driver();
            driverLocObj.PersonInfo    = new PersonInfo();
            driverLocObj.DriverLicense = new DriverLicense();
            driverLocObj.Incident      = new Incident();
            return driverLocObj;
       },
       initializeAppInfo: function(){
           var appInfoLocObj           = new ApplicationInfo();
           appInfoLocObj.Discount      = new Discount();
           return appInfoLocObj;
       },
       /*
       * Initialize Vehicle object for autoQuoteDTO.js
       */
       initializeVehicleObj: function(){
           var vehicleLocObj = new Vehicle();
           return vehicleLocObj;
       },
       /*
       * store session info
       */
       rc1Step1DTO: function(){

            var emailId = $('#save_quote_email').val();
            if (typeof emailId  !== "undefined" && emailId && emailId != '' && emailId != 'Email Address'){
                var email           = new Email();
                email.EmailTypeCd   = 'PRIMARY';
                email.EmailAddress  = emailId;
                this.postAutoQuoteObj.ApplicationInfo.GeneralPartyInfo.ContactInfo =     this.postAutoQuoteObj.ApplicationInfo.GeneralPartyInfo.ContactInfo || new Contact();
                this.postAutoQuoteObj.ApplicationInfo.GeneralPartyInfo.ContactInfo.Emails = [];
                this.postAutoQuoteObj.ApplicationInfo.GeneralPartyInfo.ContactInfo.Emails.push(email);
            }
        }
    };
    return prepareAutoQuoteDTO;
}

view - form

 <div ui-view>
<form name="DTOstep1" >
  <input type="text" name="save_quote_email" id="save_quote_email" />
  <br><br>
  <input type="submit" value="Save" />
</form>
 </div>

在此表单提交中,我想调用dtoController将json数据发送到服务器。 我没有得到如何编写函数来读取json数据并将此数据发送到服务器(API调用)。如何调用API。 API在php中将读取帖子数据。

完整代码在这里http://plnkr.co/edit/VJKrDRMJY3Q73bsCgVwX?p=preview

如果我的开发方法需要改变,请建议我。

0 个答案:

没有答案