Reputation: 61
I am trying to login from my server to another server to my other 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);
}
});
Upvotes: 4
Views: 7122
Reputation: 8345
Either your other server encounters an error (so the response is an error html page) or you will have to change the ajax type from 'jsonp'
to 'xml'
Upvotes: 0
Reputation: 276446
JSONP is basically wrapping things in a script tag and making a cross-site allowed request (since script tags do not have the same limitations that AJAX does).
Your page returns HTML (I bet the <
is part of an HTML tag) which is invalid as a JavaScript object.
Instead, use CORS to perform safe and more sensible cross-site scripting in an allowed and sensible manner.
Note: Always login with HTTPS and not HTTP (otherwise people can MITM you), and JSONP requests (being script tags injected) are always GET.
Upvotes: 1