HI,
I've got an MVVM form that submits fine, but I can't get the parsing of the incoming JSON to work.
The incoming JSOn is simply
I've got an MVVM form that submits fine, but I can't get the parsing of the incoming JSON to work.
$(document).ready(
function
() {
var
viewModel = kendo.observable({
title:
"Mr"
,
titles:[
"Mr"
,
"Mrs"
,
"Ms"
,
"Dr"
,
"Sir"
,
"Prof"
],
firstName:
""
,
lastName:
""
,
companyName:
""
,
emailAddress:
""
,
phone:
""
,
subject:
"Sales Request"
,
subjects:[
"Sales Request"
,
"Literature Request"
,
"Recruitment Question"
,
"Comment"
,
"Other Request"
],
message:
""
,
agreed:
false
,
confirmed:
false
,
hideMain:
true
,
messageID:
""
,
register:
function
(e) {
$.post(
"http://myurl/myco/tools/email_form.php"
,{
"title"
:viewModel.get(
"title"
),
"firstName"
:viewModel.get(
"firstName"
),
"lastName"
:viewModel.get(
"lastName"
),
"companyName"
:viewModel.get(
"companyName"
),
"emailAddress"
:viewModel.get(
"emailAddress"
),
"phone"
:viewModel.get(
"phone"
),
"subject"
:viewModel.get(
"subject"
),
"message"
:viewModel.get(
"message"
)
},
function
(data) {
// this is the line that raises the this.set error
// vvvvvvvvvvvvvvvvvvvvvvvvvvvv
this
.set(
"messageID"
, data.message);
// ^^^^^^^^^^^^^^^^^^^^^^^^
console.log(data.message);
},
"json"
);
e.preventDefault();
this
.set(
"confirmed"
,
true
);
this
.set(
"hideMain"
,
false
);
},
startOver:
function
() {
this
.set(
"confirmed"
,
false
);
this
.set(
"agreed"
,
false
);
this
.set(
"hideMain"
,
true
);
this
.set(
"firstName"
,
""
);
this
.set(
"lastName"
,
""
);
this
.set(
"companyName"
,
""
);
this
.set(
"emailAddress"
,
""
);
this
.set(
"phone"
,
""
);
this
.set(
"subject"
,
"Sales Request"
);
this
.set(
"message"
,
""
);
this
.set(
"messageID"
,
""
);
this
.set(
"title"
,
"Mr"
);
}
});
kendo.bind($(
"form"
), viewModel);
});
The incoming JSOn is simply
<?php
echo
json_encode(
array
(
"message"
=>
"Request submitted with ID "
.
$reqid
));
?>