我将表单数据发布到 php 并得到下面的响应,我怎样才能将这个响应变成我可以用来设置表单变量和发送电子邮件的东西?
这是调用 process.php 并发布表单数据的主干集合
define([
'jquery',
'underscore',
'backbone',
'models/postModel'
], function($, _, Backbone, postModel){
var postForm = Backbone.Collection.extend({
model: postModel,
url: 'process.php',
sync: function(method, model, options) {
var postObj = {
'name': $('#cmName').val(),
'email': $('#cmEmail').val(),
'website': $('#cmWeb').val(),
'project': $('#cmProject input[type=radio]:checked').val(),
'message': $('#contactMessage').val()
}
method = 'create';
options.timeout = 100000;
options.contentType = "application/json",
options.dataType = "json";
options.cache = false;
options.data = JSON.stringify(postObj);
return Backbone.sync(method, model, options);
},
parse: function(response) {
if(response != null) {
if (typeof response.data !== 'undefined') {
this.result = response.data;
}
}
return this.result;
},
});
return new postForm;
});
来自backbone.js 应用程序的表单帖子
{"name":"test","email":"test@test.com","website":"","project":"Web Development","message":"Testing."}
来自 php 的响应
array(1) {
["{\"name\":\"test\",\"email\":\"test@test_com\",\"website\":\"\",\"project\":\"Web_Development\",\"message\":\"$_POST$_POST$_POST$_POST$_POST$_POST$_POST\"}"]=>
string(0) ""
}
这是 php 文件的开头:
<?php
parse_str(file_get_contents("php://input"),$_POST);
$_POST = var_dump($_POST);
//$name =
//$email =