Im having trouble trying to post data correctly using jQuery/AJAX
I have the following…
<script type="text/javascript">
function notifyPPAComplete() {
$.ajax(
{
type: "POST",
url: "PsychometricTest.aspx/UpdateDB",
data: {'3'},
dataType: json,
success: success,
contentType: application/json
});
}
$.post('PsychometricTest.aspx/UpdateDB', function(data) {
alert ('success');
});
</script>
I dont seem to receive my alert after the post neither, can anybody see an obvious problem?
That’s an invalid javascript literal. You may try like this:
Notice the usage of the
JSON.stringifymethod which serializes a javascript literal into a JSON string. It’s natively built into modern browsers. And if you need to support legacy browsers you vould include the json2.js script.Also
contentType: application/jsonis pretty invalid javascript. Should be:Also:
dataType: jsonis invalid. Should bedataType: 'json'.So at the end of the day:
would successfully post to:
where MyModel: