Results 1 to 2 of 2

Thread: AJAX Source Not Working

  1. #1
    Join Date
    Feb 2013
    Location
    California
    Posts
    53
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default AJAX Source Not Working

    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).

    Code:
    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"

    Code:
    // Procedure to autocomplete by Dates
    $('.autoDate').autocomplete({
    	minLength: 1,
    	autoFocus: true,
    
    	source: function(request, response) {
    		$.ajax({
    			URL: 'files_json/auto_Timesheets_Date.php',
    			dataType:'json',
    			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.
    jdadwilson

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,920
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    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.
    Last edited by jscheuer1; 04-05-2014 at 03:44 AM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Source code not working in IE explorer
    By gmorris24 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 06-16-2010, 09:36 PM
  2. Ajax XML Ticker (txt file source)
    By stromberg76 in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 01-29-2010, 09:11 PM
  3. Ajax XML Ticker (txt file source) no source is showing
    By hups in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 07-23-2008, 07:09 PM
  4. Ajax XML Ticker (txt file source)
    By iamnewbie in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 02-13-2008, 06:05 AM
  5. Ajax XML Ticker (txt file source)
    By dholweb53 in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 01-15-2008, 08:23 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •