SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Location
    Ljubljana
    Posts
    241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jquery ajax request - datafilter problem

    Hello,

    I'm trying to set up jquery ajax request which would preprocess the returned data before decoding it to json.

    The data that is return is metatype script, I want to strip out the function call and just use the json array (argument):

    Code:
    window.google.ac.h(["test",[["test","","0"],["test internet speed","","1"],["testosterone","","2"],["testament","","3"],["test my speed","","4"],["test flash","","5"],["testicular cancer","","6"],["testmasters","","7"],["testudo","","8"],["testing","","9"]],"","","","","",{}])
    http://clients1.google.com/complete/search?q=test

    Heres my current code:
    Code:
    	$.ajax({
    	  url: 'http://clients1.google.com/complete/search?q=test',
    	  dataType: 'script',
    	  success: function(data) {
    	    alert('Load was performed.');
    		alert(data); //will show empty string
    	  },
    	  dataFilter: function(data, dataType) {
    		alert('data filter');
    		return data;
    	  }
    
    	});
    The code wont show the alert "data filter".

    Any ideas what am I doing wrong?

    How can I get the string, to be transformed to json object?
    Should data which is passed to success and dataFilter function be string or an object?
    The documentation says that script metatype is executed, which I don't want.

    Also, what do you use for debugging? I use firebug (i know for console.log function) but I somehow prefer alert thing. How do you debug your codes?

    Thanks a lot for help.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    The datatype is set to script, so the data is first evaluated as if it were a script, and the result after being evaluated is then passed to the success function.

    Could it be the script datatype and a potentially unsupported window.google.ac.h method that is getting in the way?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •