Laravel: "CSRF token mismatch.", on right code - ajax

Everything was working fine. No issue. But suddenly from nowhere this error started to show up.
"CSRF token mismatch.",
All forms was working fine and next day I open project and found this error. Very strange, how a working code started to show error all of the sudden...!!
Here is my code
$.ajax({
type:'POST',
url:"{{ route('loginuser.post') }}",
data:{_token: "{{ csrf_token() }}",email:email,password:password,remember:remember},
dataType:'json',
success:function(data){
As you can see here is I am adding csrf token in this line
data:{_token: "{{ csrf_token() }}",email:email,password:password,remember:remember},
I try to clear cache too but still didn't work. How a working code can do like this all of the sudden. Laravel is surely a strange framework!!

Related

My ajax call just stopped working

I have been using ajax call to fetch data from my remote server on my cordova app/localhost, It just stopped working for no reason, but the same ajax call is still working locally, Im using wampserver to host my site locally,
Below is the code that fails to fetch data but it has been working just fine
$.ajax({
url: 'http://wingup.byethost4.com/trial.php',
type: 'GET',
data: {phone_number:"phone_number"},
success:function(data){
console.log("message was sent");
},error:function(err){
console.log("message was not sent");
}
});
But if i change the url to my localhost it works, Please help me with annoying error
It may have the error like this
CORS header ‘Access-Control-Allow-Origin’ missing
It does not allow remote access. Check this related setting on your server.

How can I see this .json file in the browser instead of downloading it?

My desired outcome is to get air quality data on my web app.
I'm trying to use the airnowapi API to obtain the data. I use an URL they provided here, but my code fails to retrieve the data.
Here's a sample code of what I'm trying to do.
$.ajax({
url: "http://www.airnowapi.org/aq/observation/latLong/current/?format=application/json&latitude=38.3651&longitude=-114.4141&distance=250&API_KEY=[API-KEY]",
method: 'GET',
dataType: 'jsonp',
success: function(data) {console.log(data);},
error: function(){console.log("fail");}
});
It logs "fail" instead of logging the data. How can I remedy to that?
When I copy-paste the url in my browser, it downloads the .json file correctly, but I was expecting seeing it directly in the browser instead. I'm not sure if this is the origin of the problem.
Thank you!
PS.: This is my first time posting.

Cordova Ajax Bad Request

I've got a simple server app running on Heroku that I'm making ajax calls to from a Cordova app. I've setup CORS on the server app and I can call the server from my browser without any problems. However, when I call the server using the exact same code from within Cordova I get a Bad Request error!!
$.ajax({
url: 'http://{myserver}/{function}',
type: 'GET',
data: { mydata... },
success: function(resp){ alert("success"); },
error: function(err) { alert(err.statusText); }
});
I've tried adding crossDomain: true and dataType: 'jsonp', it makes no difference. I've also checked that all domains are whitelisted in Cordova <access origin="*" />
Why can't I access the server from Cordova when I can access it from my browser?
Figured it out! The reason was that I has a misspelling in data: { ... } so one of the parameters was missing.

jsonp parse to XML

I'm having the following problem.
I'm developing an app with Phonegap, and I have some trouble with the AJAX call on Blackberry.
When I call the ajax service with datatype = 'xml', it works fine on Windows Phone, and Android but failed on Blackberry.
This is the code:
jQuery.ajax({
url: requestedUrl,
dataType: 'xml',
timeout: this.timeout,
beforeSend: _.bind(this.beforeSendCallback, this),
success: _.bind(this.internalSuccessCallback, this),
error: _.bind(this.internalErrorCallback, this),
headers: {'X-Requested-With': 'XMLHttpRequest'}
})
I read on others post, that you cannot do anXMLHttpRequest to an external domain, which is the error that Blackberry shows (but I don't understand why it works on the other two platforms.) So I try to change the dataType to 'jsonp', but a syntaxError shows up. I tried with jsonp text xml, but for some reason it does not and returns the same
Uncaught SyntaxError: Unexpected token <
Looking, the response of the WS, it gave me back a valid XML. So the question is,
How can I use that XML if I'm making the call with jsonp?
EDIT:
Actually, the problem was that the "origin" header was "local:\" (my app), so BB was blocking the content of the response.
The solution was to add that domain to my config.xml, like this:
<access uri="local:///" subdomains="true" />
Unlikely Android and Windows Phone, in the config.xml you have to set access to the domains with uri, not origin and the * wildcard is not allowed with XmlHttpRequest (XHR) on BlackBerry 10.

jQuery.ajax PUT request issue in internet explorer

I am working on ASP.NET MVC4 webapi and it seems a put request via $.ajax works fine in case of google chrome and Firefox but it isn't workin in IE(10).
The below code :
$.ajax({
url: 'api/xQuizQuestion',
type: 'PUT',
dataType: 'json',
data: JSON.stringify(AllQsWithAs),
contentType: "application/json;charset=utf-8",
success: function (data) {
alert('Student added Successfully');
},
error: function () {
alert('Student not Added');
}
});
Works fine in chrome/firefox, in sense that the data AllQsWithAs(which is an array of Complex types) gets added to the Request body, but in case of IE(10) the request body is sent without the Data.
Confirmed the same with Fiddler as well.
Surprisingly it works just fine when I change my Browser Mode to IE9/IE8 or Browser mode to IE 8/9.
Not sure whats the issue. Any help/insight would be appreciated.
Seems to be a bug in IE 10.
I'm finding reports that adding this tag to your head will run the scripts in compatibility mode.
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" >
http://code.gishan.net/code/solution-to-ie10-ajax-problem/
Old bug tracker entry for jQuery closed as can't fix: http://bugs.jquery.com/ticket/12790
I'm having trouble finding a good source, but it may have been fixed in the latest and greatest IE10 release.

Resources