AJAX (jQuery based) failing in WAMP
Posted by: ashcanschool (---.range31-51.btcentralplus.com)
Date: August 30, 2014 09:36AM

Version of Operating system? - 64bit
Version of Wamp Server installed? - 64bit
Version of Apache you are running? - 2.4.9
Version of MySQL you are running? - 5.6.17
Version of PHP you are running? - 5.5.12

What colour is your WampManager icon? - Green

Do you have a HOSTS file? - Yes

I've set up a WAMP server to build and test a website. It's my first time and it's going swimmingly until I get to anything involving AJAX (jQuery based).

Basic start is a user login form. Submit button goes to JavaScript function which has an AJAX call within to check the database for user etc etc. This was failing. Google's Dev Tools were saying the issue was "unexpected token <" at line whatever. The line was when the AJAX returned.

Reading up this seems to be an issue when the AJAX is returning a blank html page "" which is not valid JavaScript and thus throws this error. And in this context I'm guessing it would throw this if say a 404 page was being throw up if the php could not be found.

So I crawled over that for an hour with no joy. Then I mocked up a simple version of the AJAX and ran that hoping to build the user login form again step by step to find my issue. That didn't work.

On a hunch I build the exact same thing on a real server (LAMP) and found that it did indeed work. So now I'm guessing that my issue has something to do with a WAMP server setup. I was led to believe that AJAX calls would just work from setup.

Any ideas of what might be causing this and where to go to look for info on how to setup WAMP correctly for jQuery and AJAX?

More obscure attempts involved swapping out:

[localhost]
for
[127.0.0.1]

which threw a "No 'Access-Control-Allow-Origin' header is present on the requested resource." error. I thought great Apache is on a different port. Nope Apache is on port 80.

Attempted to add in:

crossDomain: true;
dataType: "jsonp",

to the AJAX call and returned a: "Resource interpreted as Script but transferred with MIME type text/html" but this returned to the "unexpected token <" error.

I'm running out of ideas, so if you have any I'd be appreciative.

Options: ReplyQuote
Re: AJAX (jQuery based) failing in WAMP
Posted by: RiggsFolly (---.dynamic.dsl.as9105.com)
Date: August 31, 2014 02:41PM

Take it from me, AJAX works just fine on WAMPServer. I use it all the time.


"unexpected token <" at line whatever

This looks like a PHP error message. If you see this in the result of the AJAX call it is usually that you are getting a PHP error message returned to you javascript from your called PHP script. So check the called script.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: AJAX (jQuery based) failing in WAMP
Posted by: sbenders-abbyy (12.207.17.---)
Date: January 07, 2016 02:23AM

Adding On to this old topic:

I have run into the exact same issue.

I had a web app that I wanted to run with WAMP, and I was upgrading from Apache 2.2 and PHP 5.2.17 to WAMPServer 2.5.

In trying out the old code, I ran into this same issue, complete with :
"Uncaught SyntaxError: Unexpected token <"

I think I've narrowed the issue down to being a PECL extension issue: the PHP version included with this version of WAMP does not have the pecl_http/php_http extension, which is what I was using to make my jQuery AJAX calls through PHP.

I say this, because in the error message, I'm able to read this line:
"Fatal error: Call to undefined function http_parse_message() in [my .php script file location]"

Which, as far as I can tell, means that the extension isn't present or incompatible with this version of PHP (5.5.12). As I check phpinfo, I'm not seeing the extension displayed, which probably means the one I've loaded in (1.4? 1.7?) is incompatible.

That being said, I think I have to look at a newer version of the extension (in whatever new forms it takes: [pecl.php.net]), or alternate ways of making the request (cURL).

Options: ReplyQuote


Sorry, only registered users may post in this forum.