In jQuery, I am referencing https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js . But I think I have problems with jQuery's $.post() when I follow their template very closely, i.e.,
$.post( "test.php", { func: "getNameAndTime" }, function( data ) {
console.log( data.name ); // John
console.log( data.time ); // 2pm
}, "json");
Here's my code:
$( document ).ready(
function () {
var javaObj = {
_dataFreq: "0"
, _period: $( "#interval" ).val()
, _time: $( "#dayTo" ).val() + ".00"
, _ptNames: $( "#ptNames" ).val().split( ',' ) //string[]
}
$.ajax( {
type: 'POST'
, url: mySrvEndPont
, data: JSON.stringify(javaObj)
, success: function ( response ) {
alert( "OK");
}
, error: function ( e ) {
alert( e );
}
, contentType: "application/json"
, dataType: "json"
} );
$.post( mySrvEndPont, JSON.stringify(javaObj), function ( response )
{
alert( "OK" );
} , "json")
;
} );
I got "OK" and a valid response object from $.ajax(), but nothing except a 400 bad request from $.post() !!! Just want to know why.