Siteground Laravel 500 internal server error ajax randomly - ajax

My website is built in laravel 5.4 and hosted on Siteground. The website was working fine before. But now I am randomly getting 500 internal server errors on some ajax request.
Sample code:
var csrf_token = $('meta[name="csrf-token"]').attr('content');
var postdata = {
'_token': csrf_token
};
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: url,
type: 'POST',
dataType: 'JSON',
data: postdata,
success: function(data) {
},
error: function(data) {
}
});

I had this problem too, randomly, in my AJAX requests, the env() function did not work.
That causes 500 errors because the application can't get config variables and i just got a message: 500 Server Error. Since i replaced the env() calls in my config files, all works fine.
So for exemple in config/app.php, this not work:
'key' => env('APP_KEY'),
But this works
'key' => 'MY_APP_KEY_HARDCODED',
Now the trick is to find why env() does not work sometimes...
I discovered the reason thanks to laravel debugbar: https://github.com/barryvdh/laravel-debugbar

Related

ColdFusion 2016 Ajax

I'm trying to figure out what is Adobe Coldfusion and how to work on this platform.
I'm stuck at simple issue.
On submit I send form with jQuery ajax to server.
But I got response: 500 (Element MY_VAR is undefined in FORM.)
What I'm doing wrong?
JS
$loginForm.on('submit', function(e) {
e.preventDefault();
var formData = new FormData(e.target);
$.ajax({
url: 'test.cfm',
method: 'POST',
cache: false,
processData: false,
data: formData,
error: function(err) {
console.log(err);
},
success: function(data, status) {
console.log(status);
console.log(data);
}
});
});
CF
<cfoutput>
<p>#form.myvar#</p>
</cfoutput>
500 indicates an internal server error.
Are you trying to display your form values after sending them?
Maybe try and use the cfdump tag. Very useful for debugging.
Try dumping the form scope and see what variables are actually in there.

JQuery - Ajax - Set Request Header - DocuSign

Afternoon!
I a trying to send a get request usng jquery/ajax and I need to set headers. When I try setting the headers using Chrome's REST app, it woks fine and returns what I need.
I am watcing the headers in Firebug hen I run this code:
$.ajax({
url: urlLoginCall,
type: 'GET',
headers: {'Accept': 'application/json'},
success: function(r){
alert("success");
},
error: function(){
alert("failure");
}
});
The above works fine and I get a failed response, since I am not including the authorization info in the headers. But it at least shows me something in Firebug that I am setting the header Accept.
When I try to add the X-DocuSign-Authentication header, i get the failed alert, but nothing comes up in Firebug:
$.ajax({
url: urlLoginCall,
type: 'GET',
headers: {'X-DocuSign-Authentication': jsonLoginCall},
success: function(r){
alert("success");
},
error: function(){
alert("failure");
}
});
Any ideas would b helpful. Thanks!

Ajax returning 404 error on ASP MVC3 site

This Ajax code works perfectly is I'm running the program on my local machine. However, once we put this out on a DEV server we get a 404 error. The site is an ASP MVC3 site that communicates with a SQL database, and the rest of the site has no problem doing so. I'm brand new to Ajax so I'm not quite sure where to look. Could this be an issue with IIS as well?
Ajax code
var request = $.ajax({
type: 'POST',
url: '/BatchPrograms/PopDetails',
data: { 'programName': pgmname },
dataType: 'text',
success: function (data) {
console.log(data);
alert(data);
//$('#data').dialog('open');
},
error: function (data) {
console.log(data)
alert("Unable to process your resquest at this time.");
}
});
Chrome's Console error message:
POST http://insideapps.dev.symetra.com/BatchPrograms/PopDetails 404 (Not Found)
send jquery-1.8.3.js:8434
jQuery.extend.ajax jquery-1.8.3.js:7986
GetProgramDetails BatchDashboard:51
onclick BatchDashboard:165
Chome's Network error message
Name (Path) Method Status (Text) Type Initiator Size Time (Latency)
PopDetails POST 404 Not Found Text/Html jquery-1.8.3.js:8434 1.8KB 21ms
/BatchPrograms Script 1.6KB 17ms
Try modifying url to
url: '#Url.Action("PopDetails", "BatchPrograms")'
Try using the Url.Action() helper to get the route from the Table Routes defined in your application.
var request = $.ajax({
type: 'POST',
url: '#Url.Action("PopDetails", "BatchPrograms")',
data: { 'programName': pgmname },
dataType: 'text',
success: function (data) {
$('#data').dialog('open');
},
error: function (data) {
alert("Unable to process your resquest at this time.");
}
});

Google app engine JSON/AJAX not working

Here is my JS code:
<script>
$("#comments").click(function(event) {
$.ajax({
type: "GET",
url: '/localhost:8080/comment',
data: JSON.stringify(
{
'name': 'anon',
'subject': 'MY COMMENTS',
}),
contentType: 'application/json',
success: function(data,textStatus, jqXHR) {
console.log('POST response: ');
console.log(data);
}
});
});
</script>
and here is my Python Code:
class Guestbook(webapp2.RequestHandler):
def get(self):
Jguest_data = json.loads(self.request.body)
return self.response.out.write(json.dumps(Jguest_data))
I got the error 404 Resource not found. After digging around there is some issues with localhost . so I tried with JSONP as follows:
<script>
$("#comments").click(function(event) {
$.ajax({ // ajax call starts
url: "localhost:8080/comment", //
type: "GET",
data: JSON.stringify(
{
'name': 'anon',
'subject': 'MY COMMENTS',
}),
dataType: "jsonp", // Choosing a JSON datatype
success: function(data,textStatus,jqXHR)
{
console.log('POST response: ');
console.log(data);
}
});
});
</script>
That still does not work... I get "No JSON object could be decoded" Error.
I tried replacing JSON.loads with JSON.load... and that still errors out...
Can someone please let me know what the issue is?
Thanks a mil in advance
when you do a GET request with ajax you are using url parameters.
so there is no body in the request.
make a POST and change your get() to post()
You should edit your app.yaml file if there is one in your project, and if there is not one, add one.
Add this code to your file (app.yaml).
-url: /comment
script: <url-to-the-server-side-script>
You can see a more complete app.yaml documentation for use with python here.
https://cloud.google.com/appengine/docs/python/config/appref

Jquery AJAX for fetching JSON, affected by URL prefix (www vs. no www)?

I have come across a peculiar item in JQuery that I am hoping somebody can help me to understand.
I've spent much of the day trying to get JQUERY's AJAX 'success' function to be raised when returning JSON from the server.
I checked the JSON # JSONLint to ensure validity, checked encoding, tried different headers, but still PROBLEMS.
After a couple hours, I switched the url (by accident!)
from
http//www.testing.com/_r4444/myfile.php
to the exact same thing WITHOUT the www... and it suddenly worked.
I have no clue why this would be the case - any ideas?
the snippet follows
$(document).ready(function() {
$.ajax( {
type: "POST",
contentType: "application/json",
url: "http://testing.com/_r4444/getter.php",
beforeSend: function(x) {
if(x && x.overrideMimeType) x.overrideMimeType("application/json;charset=UTF-8");
},
data: "pass=TEST",
dataType: "json",
error: function (xhr, status) {
alert(status);
},
success: function (result) {
alert(result);
}
});
});
Are you using "www" on the page in the browser?
Try switching the call to not include the domain, like:
"/_r4444/getter.php" instead of the full domain.

Resources