1

I'm using the following AJAX in my project

    var _getWeatherInfo = function(ntown){
    //Debugging
    console.log("Before dojo.xhrget");
      //dojo ajax request used to call the PHP file and retrieve the towns data
      dojo.xhrGet({
          handleAs: "json",
          timeout: 5000,
          //php file URL (location)
          url: "PHP/weather.php?ntown=" + ntown,

          load: function(results) {
              //send the results to the function _refreshWeatherList
              _refreshWeatherList(results);               
        }

    });
    //Debugging
    console.log("After dojo.xhrget");
}

In order to retrieve weather data for cities/towns. However, its been a while since i worked on this project and i'm having trouble understanding why this is no longer working (it was working last time i ran this project).

In the browser console im getting the following error:

SyntaxError: Unexpected token <
    at Object.b.fromJson (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:227:426)
    at Object.b._contentHandlers.b.contentHandlers.json (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:185:216)
    at t (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:189:392)
    at c (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:75:221)
    at d (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:75:10)
    at resolve.callback (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:76:350)
    at http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:192:378
    at k (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:196:406)
    at n (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:196:332)
    at resolve (http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js:198:406)y @ dojo.js.uncompressed.js:14021(anonymous function) @ dojo.js.uncompressed.js:13981c @ dojo.js.uncompressed.js:4579d @ dojo.js.uncompressed.js:4560reject.errback @ dojo.js.uncompressed.js:4655c @ dojo.js.uncompressed.js:4594d @ dojo.js.uncompressed.js:4560reject.errback @ dojo.js.uncompressed.js:4655c @ dojo.js.uncompressed.js:4590d @ dojo.js.uncompressed.js:4560resolve.callback @ dojo.js.uncompressed.js:4640(anonymous function) @ dojo.js.uncompressed.js:14208k @ dojo.js.uncompressed.js:14488n @ dojo.js.uncompressed.js:14479resolve @ dojo.js.uncompressed.js:14643a @ dojo.js.uncompressed.js:14532k @ dojo.js.uncompressed.js:14503n @ dojo.js.uncompressed.js:14479resolve @ dojo.js.uncompressed.js:14643a @ dojo.js.uncompressed.js:14532k @ dojo.js.uncompressed.js:14509n @ dojo.js.uncompressed.js:14479resolve @ dojo.js.uncompressed.js:14643a @ dojo.js.uncompressed.js:14532k @ dojo.js.uncompressed.js:14503n @ dojo.js.uncompressed.js:14479resolve @ dojo.js.uncompressed.js:14643r @ dojo.js.uncompressed.js:11883f @ dojo.js.uncompressed.js:11909

I'm including dojo using:

<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>

xhr Response:

"<!--Include Database connections info-->


↵↵( ! ) Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in E:\Program Files (x86)\wamp\www\Weather-Widget-App-master\PHP\configHome.php on line 6↵Call Stack↵#TimeMemoryFunctionLocation↵10.0004244528{main}( )..\weather.php:0↵20.0006248360include( 'E:\Program Files (x86)\wamp\www\Weather-Widget-App-master\PHP\configHome.php' )..\weather.php:2↵30.0006248936http://www.php.net/function.mysql-connect' target='_new'>mysql_connect↵( )..\configHome.php:6↵↵
↵↵( ! ) Warning: mysql_select_db() expects parameter 1 to be string, resource given in E:\Program Files (x86)\wamp\www\Weather-Widget-App-master\PHP\configHome.php on line 9↵Call Stack↵#TimeMemoryFunctionLocation↵10.0004244528{main}( )..\weather.php:0↵20.0006248360include( 'E:\Program Files (x86)\wamp\www\Weather-Widget-App-master\PHP\configHome.php' )..\weather.php:2↵30.0300257280http://www.php.net/function.mysql-select-db' target='_new'>mysql_select_db↵( )..\configHome.php:9↵↵Error selecting specified database on mysql server: "

4
  • 2
    Does the xhr request receive a response? can you post it? I'm wondering if your server is returning malformed json.
    – Russell
    Commented Nov 11, 2015 at 7:09
  • Sounds like the server responds with XML not JSON
    – baao
    Commented Nov 11, 2015 at 7:45
  • Sorry for the late reply. I did some further work and I found some helpful info in the xhr response (thanks Russell for your suggestion!).
    – Corey
    Commented Nov 14, 2015 at 21:45
  • Update: From the xhr response, i obviously had some errors with my SQL connection/statements. All fixed up now. Thanks for your help.
    – Corey
    Commented Nov 14, 2015 at 22:42

2 Answers 2

1

My issue was invalid/depreciated mysql. I rewrote my MYSQL with MYSQLi and everything fell into place.

0

I had this issue when returning a JSON from a service in which I previously var_dumped something. Uff. Hope it helps someone because I wasted 10 minutes to find the reason for that.

Not the answer you're looking for? Browse other questions tagged or ask your own question.