View Full Version : AJAX Source Not Working

03-19-2014, 05:06 AM
I need to implement an AJAX call to a JSON routine but I need to pass a dynamic variable so that the response will be filtered. The following source parameter works fine, but the passed variable is not really dynamic in that the value passed is that which was loaded on initialization (its just the way autoComplete works).

source: 'files_json/auto_Timesheets_Date.php?tsEmpNum=' + $('#ts_EmpNum').val(),

The following source parameter does in fact pass the latest ts_EmpNum BUT the response from the JSON is the HTML code one would see if doing a "View Page Source"

// Procedure to autocomplete by Dates
minLength: 1,
autoFocus: true,

source: function(request, response) {
URL: 'files_json/auto_Timesheets_Date.php',
data: {
tsEmpNum: $('#ts_EmpNum').val(),
term: request.term
success: function( data ) {
response( data );

select:function(evt, ui)
form_edit.ts_Date.value = ui.item.tsDate;
form_edit.ts_Status.value = ui.item.tsStatus;
});// End of autoDate

Does anyone have a clue as to why the source parameter is returning the HTML and not the JSON data?

Any assistance is greatly appreciated.

04-05-2014, 02:55 AM
Assuming everything else is right, you cannot get json unless there is json. That is the fetched file must be able to be read as valid json data. Otherwise jQuery will (depending upon version) return text or just an error. You might have better luck reading it as or converting it to xml and reading/parsing it as such.

Or it could be that the response function (which I don't believe you've shown) is converting the json object to text. Or it could be something else.

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.