Using this calendar tool here, http://bootstrap-calendar.azurewebsites.net/.
I am getting an issue inside calendar.js on this line of code:
Calendar.prototype._loadTemplate = function (name) {
if (this.options.templates[name]) {
return;
}
var self = this;
$.ajax({
url: self._templatePath(name),
dataType: 'html',
type: 'GET',
async: false,
cache: this.options.tmpl_cache
}).done(function (html) {
self.options.templates[name] = _.template(html);
});
};
The browser is throwing 'Failed to load resource: the server responded
with a status of 500 (URL Rewrite Module Error.)
The strange thing is that I dont get any error on my local machine, but I only get error when running this code via server (IIS).
Even on server, this error is not shown always. It comes randomly whenever I refresh the page.
Any idea, whats the issue?
I just found out there was some port forwarding issue on IIS Server, I was using host name on the URL like www.tilda.com, I replaced it with the actual URL of the server and now I am not getting any issue.
Thanks.
Related
I'm building an application using laravel. I have a controller which returns a session parameter from the server.
I'm retrieving this parameter using an ajax request from a view blade as follow:
var url = CMS_URL + 'GetSystemMode/';
$.ajax({
url: url,
type: 'get',
dataType: 'text',
async: false,
success: function(data) {
console.log("data: " + data);
}
});
The code running on the server side is:
Route::get('/GetSystemMode', function () {
return Session::get('systemMode');
});
In localhost, I'm getting the right "data" and the code works as a charm, but in production, "data" is always empty.
It's like the success method is executed before the data is yet retrieved from the server side.
This issue took to much time from me, and I don't have any idea how to fix it.
Thanks.
Our production environment was at the appEngine, so due to the server restirctions, it wasn't allowed to save the sessions on files as was done on localhost. So the problem was actually that the server is not saving the sessions at all and therefor I'm getting empty data.
I solved it by installing redis and saving the sessions over it.
when i try to click the share button i get Failed to load resource: the server responded with a status of 500 (Internal Server Error) in the console and alert says Ajax request has encountered an error knowing that this doesn't happened on staging just on production and on safari or firefox.
I spent hours trying to figure it out
here is my code
$(document).on("click",".btn-share-generate-js",function(e) {
var url = $(this).data("share-url");
var id = $(this).data("id");
var message = $("input:radio.vt:checked").val();
var clickedBtn = $(this);
clickedBtn.find(".icon-link").addClass('hide');
clickedBtn.find(".icon-arrows-cw").removeClass('hide');
$.ajax({
type: "POST",
url: url,
dataType: 'json',
data: {
'share[message]': message
},
success: function(data) {
clickedBtn.find(".icon-link").removeClass('hide');
clickedBtn.find(".icon-arrows-cw").addClass('hide');
if (data.error == true) {
alert(data.error_message);
} else {
replaceShareButtonWith(data.share_url);
}
},
error: function(){
clickedBtn.find(".icon-link").removeClass('hide');
clickedBtn.find(".icon-arrows-cw").addClass('hide');
alert("Ajax request has encountered an error.")
},
});
return false;
});
$(document).on("click",".social-media-reshare-btn",function(e) {
var url = $(this).attr("href");
window.open(url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=245,width=550');
return false;
});
thanks
If your server responds with a 500 error, the only reason is that you are sending a slightly different request causing the server-side misbehave. You should open the developer console (of Safari and/or Firefox), switch to the Network tab, and retry the action. Now you can inspect the entire outgoing request to see how it is different from the browsers that work fine.
Once you have the root cause of the problem, you can decide either
the client is sending something wrong: so now you determine how to fix the above code
the server should not fail given this slightly different incoming request: so you should fix the server code
I have a pyramid application that runs perfectly on a local server, but when I move it over to a web server (Dreamhost), I get the following error:
400 Bad Request:
Bad request (GET and HEAD requests may not contain a request body)
The code in question is the following ajax in Javascript:
function summary_ajax(sName){
$.ajax({
type: "POST",
url: "summary",
dataType: "json",
data: {
'ccg_name': sName,
},
async: false,
success: function(data) {
//alert("In ajax success function") <----------- This never executes
lValues = data.lValues;
lLabels = data.lLabels;
},
});
};
return (lValues, lLabels);
And is handled in views.py:
#view_config(route_name="ccg_map_summary_ajax",renderer="json")
def ccg_map_summary_ajax(self):
sCCG = self.request.POST.get('ccg_name')
fData = open('pyramidapp/static/view_specific_js/ajax_summary_data.js')
dData = json.load(fData)
lLabels = dData[sCCG].keys()
lValues = dData[sCCG].values()
return {
'lLabels' : lLabels,
'lValues' : lValues,
}
I did some testing by placing alert() functions (its slow, because the server only reloads the script every so many minutes), and everything executes fine except for alerts in the ajax call. So it seems that either the post fails, or something goes wrong in the view. Any ideas?
So is there something in this code that works in my local server (in Pyramid) but breaks down in the web server (Dreamhost)?
The file structure is the same in the local and web server. I don't see why it shouldn't, but will fData still open the file for reading?
For anyone else out there, I found the problem:
The path I specified above was a relative path that worked on my system but not on the server because the working directories are obviously different. So instead of using a relative path, I just changed the script to have the correct absolute path.
To find the current working directory path, just enter pwd into terminal.
I have been trying to load a JSON file from a cross-domain server. I've tried examples from stackoverflow and from the jQuery docs. I did get it working in a previous project, but now it strangely does not. The error returned from jQuery is unreadable to me. What can possibly go wrong here?
$(document).ready(function() {
console.log("Start loading");
$.ajax({
type: 'GET',
url: "http://www.nightoferror.nl/data/data.json",
dataType: 'jsonp',
crossDomain: true,
error: function(data) {
console.log('error', data);
},
success: function(data) {
console.log('success', data);
}
});
});
And the erratic JSFiddle here: http://jsfiddle.net/ZuyJV/4/
Content-Type:application/javascript
rather than Content-Type:application/json;
Could it be because your file is named .js, that Apache is serving the content type itself?
Try changing the file type, to JSON and setting up Apache to serve that filetype with the correct MimeType.
I found this using Fiddler - A HTTP Debugger.. open Fiddler(2), make your request in your browser and Fiddler2 then picks it up. From there, just checked the response for your file.
It looks like your server is returning the response as "Application/Javascript"
I am trying to login to a website using a known username and password and to get some data displayed from the site for a specific user account on that website. I am using jQuery and Ajax for this purpose. This is my code:
$.ajax({
async: false,
cache: false,
type: 'POST',
dataType: 'json', // json...just for example sake
data: ({
'login_username': username,
'secretkey': password
}),
url: 'https://mail.someserver.com/src/redirect.php',
success: function (data) {
alert("SUCCESS!")
if (data === '1') { // server returns a "1" for success
// success!
// do whatever you need to do
} else {
// fail!
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// something went wrong with the request
alert("Failed!");
}
});
I've already made my search around the web and I know that browsers do not permit cross server ajax calls to prevent security issues, but I've already tried to use "jsonp" as dataType to no avail :(
So, what am I doing wrong?
Be sure that your url is not breaking the same origin policy -- that is, the request coming from the client cannot request data from a server from a different domain (there are exceptions to this rule, namingly CORS, but that requires that you make changes to the server/application you're talking to).
The solution to your problem would be to make the request from some server-side script, then in turn having your client application query that script, based on the same machine that's serving the application to the web.
My fault isn't at the code above, my fault was that in my manifest file (I am building a Google Chrome extension) I didn't have set proper permissions (https://*).
Sorry for the frustration!