Ajax Error: SyntaxError: Expected expression, got '<'

I am trying to login from my server to another server to another site. But this error comes every time.

SyntaxError: expected expression, got '<'

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E

      

Please, help.

url = "http://www.example.co.uk/email/admin/index.php?Page=&Action=Login";
//        console.log(url);
//        return false;
        postData = {ss_username:"username",ss_password:"password",Action:"login"}
        $.ajax({ //update page and redirect
          type: 'POST',
          url: url,
//          crossDomain: true,
          dataType: "jsonp",
          data: postData,
          success: function (response) {
            console.log(response);

          },
          error: function (response) {
            console.info(response);
          }
        });

      

+3


source share


2 answers


JSONP basically wraps things in a script tag and makes an allowed cross-site request (since script tags don't have the same restrictions that AJAX does).

Your page is returning HTML (I'm pretty sure it <

is part of an HTML tag), which is not valid as a JavaScript object.



Use CORS instead to make safer and smarter cross-site scripting in a valid and sane way.

Note. Always login with HTTPS, not HTTP (otherwise people can MITM you) and JSONP requests (being injected by the script) are always GETs.

+1


source


Either your other server is facing an error (so the response is an error html page) or you have to change the ajax type from 'jsonp'

to'xml'



0


source







All Articles