I’m sending a jQuery (version 2.2.4) AJAX request and getting a jQuery parse error if I include “??” in the URL. For info on “??”, see the “data” portion of the jQuery.ajax docs.
To debug I removed all the extra URL params and added them back one-at-a-time to find out what was causing the parse error. The request is going to the server and being handled and JSON data is being returned. When it work, it works.
NOTE: The URLS below were copied from the Network tab of the Chrome debug console showing the actual GET requests sent to the server, so they’ve been process by jQuery.
NOTE: The “gstr_*” variables are all Strings and defined elsewhere.
When this URL is sent, it works. It calls the “success” handler and the data returned is JSON. Note that the “jqtag” URL param at end of URL is empty.
https://s01-sbm-test.example.com/workcenter/tmtrack.dll?ScriptPage&scriptUUID=60ec112b-8630-4a37-a268-163f2c967c61&callFrom=URL&userid=&prjid=&tblid=1179&itemid=1&issueid=65150799&method=GET&src=jQuery_url&jqtag=&_=1727293513409
Adding the “??” as a value to the “jqtag” URL param before calling the .ajax function causes it to fail with this error:
Error handler :: status=parsererror ; error=SyntaxError: Unexpected token ‘:’
https://s01-sbm-test.example.com/workcenter/tmtrack.dll?ScriptPage&scriptUUID=60ec112b-8630-4a37-a268-163f2c967c61&callFrom=URL&userid=&prjid=&tblid=1179&itemid=1&issueid=65150799&method=GET&src=jQuery_url&jqtag=jQuery22408158756807991197_1727293897743&_=1727293897744
Here is the data printed by the “dataFilter” handler. I’ve hard-coded the server app to send this response irrespective of params sent.
DataType = "json"
Data = "typeof = string"
Data = "{
"arrayData" : [1, 2, "3", 4],
"name" : "myObjName",
"value1" : 17,
"value2" : 5.700000
}"
Here’s the function called to do the GET request:
const getDataDemo4_GET = () => {
let obj_demo4_ajax_get_results = {};
let ajax_get_settings = {
method: "GET",
async: false,
cache: false, // appends "_={timestamp}" to the GET parameters.
contentType:
"application/x-www-form-urlencoded; charset=UTF-8", // type of data we send
dataType: "json", // type of data we expect
// DEBUG :: print the data from server before jQuery processes it.
dataFilter:
function(str_data, str_dataType) {
console.log(`*** dataFilter *** "Call_ModScript_From_Form.js" jquery.Ajax GET dataFilter handler
DataType = "${str_dataType}"
Data = "typeof = ${typeof(str_data)}"
Data = "${str_data}"
`);
return str_data;
} ,
success:
function(obj_data, str_status)
{
console.log(` SUCCESS *** jquery.Ajax GET success handler ... status=${str_status}`);
obj_demo4_ajax_get_results = obj_data;
},
error:
function(jqxhr, str_status, str_err)
{
console.error(`"Call_ModScript_From_Form.js" jquery.Ajax GET error handler ... status=${str_status} ; error=${str_err}`);
},
};
// Call the ModScript.
console.log(` URL to send: "${gstr_modscript_url + "&userid=" + gstr_userid + "&prjid=" + gstr_prjid + "&tblid=" + gstr_tblid + "&itemid=" + gstr_recid + "&issueid=" + gstr_issueid + "&method=GET" + "&src=jQuery_url" + "&jqtag=??"}"`);
let jq_ajx_get = jQuerySBM.ajax(gstr_modscript_url + "&userid=" + gstr_userid + "&prjid=" + gstr_prjid + "&tblid=" + gstr_tblid + "&itemid=" + gstr_recid + "&issueid=" + gstr_issueid + "&method=GET" + "&src=jQuery_url" + "&jqtag=??" ,ajax_get_settings);
console.log("*** obj_demo4_ajax_get_results:");
console.table(obj_demo4_ajax_get_results);
}
8