I have 2 webpages where the code works on one page but on the other page it won't work. The code is supposed to open a new window with the submitted file to display the submitted file. For some reason it won't do it on the page that fails.
The code that is taken from moodle is:
function openDV(dvtype, submission_id, coursemoduleid) {
alert('i opendv');
$.ajax({
type: "POST",
url: "../../plagiarism/turnitin/ajax.php",
dataType: "html",
data: {action: dvtype, submission: submission_id, cmid: coursemoduleid},
success: function(data) {
alert('i success');
$("."+dvtype+"_form_"+submission_id).html(data);
alert('i success 2: '+"."+dvtype+"_form_"+submission_id);
$("."+dvtype+"_form_"+submission_id).children("form").on("submit", function(event) {
alert('debug 2');
dvWindow = window.open('', 'dv_'+submission_id);
dvWindow.document.write('<frameset><frame id="dvWindow" name="dvWindow"></frame></frameset>');
dvWindow.document.close();
$(dvWindow).bind('beforeunload', function() {
refreshScores(submission_id, coursemoduleid);
});
});
alert('i success 3');
$("."+dvtype+"_form_"+submission_id).children("form").submit();
$("."+dvtype+"_form_"+submission_id).html("");
},
error: function() {
alert('error!');
}
});
}
On the failing page, the code that is alert('debug 2'); is not reached. Why?
It's not part of the Moodle core code, so I'm guessing its a download of this plugin?
https://moodle.org/plugins/view/plagiarism_turnitin
There are 2 versions though, the old one is at https://github.com/danmarsden/moodle-plagiarism_turnitin
The latest one is at https://github.com/jmcgettrick/moodle-plagiarism_turnitin
I had a very quick look and couldn't see the ajax code.
Where did you download the code from? Also what version of Moodle are you using? Maybe check you are using the latest version of the plugin for your version of Moodle.
UPDATE: The Moodle page above says that the turnitin module needs to be installed too. Is this installed on the destination server?
https://moodle.org/plugins/view/mod_turnitintooltwo
UPDATE 2: Ah yes, the ajax code is in turnitintooltwo
https://github.com/jmcgettrick/moodle-mod_turnitintooltwo/blob/master/jquery/turnitintooltwo.js
It looks like the code your are using is out of date.
Related
I'm trying to debug problems in a javascript file. When I make a change to the file and start the Visual Studio Debugger (F5) a [dynamic] version of the javascript file shows up in the debugger and stops at my break point, but the change I made to the file is not reflected in the [dynamic] version. For example, here is the function in the javascript file:
function GetJobNotes(ScheduleID) {
var par = "ScheduleID='" + ScheduleID + "'";
$.ajax({
type: "Post",
url: "MaskingScheduleService.asmx/HelloWorld",
//data: par,
dataType: "xml",
//success: GetInfoSuccess,
//error: ProcessError
});
alert("ajax called");
}
and here is what shows up in the [dynamic] version of the file when debugging:
function GetJobNotes(ScheduleID) {
var par = "ScheduleID='" + ScheduleID + "'";
$.ajax({
type: "Post",
url: "services/MaskingSchedule.asmx/GetJobNotes",
data: par,
dataType: "xml",
success: GetInfoSuccess,
error: ProcessError
});
}
How do I get the [dynamic] version to match the code in my javascript file?
The issue is that there is an option in Chrome that breaks the updated js file. With that option, Chrome will block the changed js content and always use the previous js content.
Solution
When starting vs debugging under Chrome, please press F12 and then select Network menu.
This is an option called Disable cache
Check this option and then refresh your web page and it will load the latest version of the javascript file.
EDIT 2
I still need help, as the error still isn't fixed.
Below I have added a link to a screenshot of what .ajaxError() does throw:
http://i.imgur.com/RkcgNtG.jpg
Another thought was the server setting. Is there any chance that suphp or the mpm_itk module are the cause for this bug?
EDIT
I have figured out something. My Ajax-Call should update some data from an input and a textarea. I tested some more and saw that the 403 only occurs when the value of my textarea or the value of my input has more than one whitespace ... So 'that-is-a-test' and 'thatisatest' work fine, but 'that is a text' returns a 403.
I also want to add that the Ajax-Call is done with a get-method.
Original
I've got a problem working on my cakePHP project.
First of all I have to say that I am new to cakePHP and that I work on a project that was not developed by me initially.
I have set up this project on my localhost (Windows 8 with xampp) and everything works fine.
In a next step I edited the Bootstrap-Configuration file, corrected the database information and uploaded all files to my server.
Now everything still works, except for the jQuery AjaxCalls. Tracing the root of this error I saw that the server returns an 403 Status Code.
Now I searched for possible reasons. First aspect I found was to set the security-level from high to medium. But as my 2.x project does not have this setting anymore, I need another solution.
Next step was to check the server settings. But the phpinfo of both, my local version and the server where the error takes place, seem to be nearly the same.
Only the PHP version of 5.3 on the server and the use of FastCGi are different.
But as cakePHP do not need more than 5.2 that cannot be the reason.
So now I have no idea what to search for. I think it has to be one setting because it works fine on my localhost, worked fine on another server but fails on the new server.
Any ideas I could check? As I am not an expert of server technologies it would be great if you answer as detailed as possible.
thanks and greets
I have now changed my jQuery Ajax-Call that looks like following
$.ajax({
url: '/metas/saveMetas',
data: {
"model": model,
"f_key": f_key,
"pagetitle": pagetitle,
"keywords": keywords,
"description": description,
"niceurl": niceurl
},
dataType: 'json',
complete: function(){
return false;
},
success: function(result) {
if(typeof result =='object') {
$('#modal-spinner-seo-update').hide('slow');
jQuery.each(result, function(field, message) {
$('#seo-'+field).next('div.error-message').html(message).fadeIn('fast');
});
} else {
$('#modal-spinner-seo-update').hide('slow', function() {
$("#seo-widget-message-success").fadeIn('slow').delay(2000).fadeOut('slow');
});
}
return false;
}
});
into a simple JavaScript xmlHttpRequest as following
xhr = new XMLHttpRequest();
xhr.onreadystatechange=function()
{
if (xhr.readyState==4 && xhr.status==200)
{
console.log(xhr.responseText);
if(typeof xhr.responseText =='object') {
$('#modal-spinner-seo-update').hide('slow');
jQuery.each(result, function(field, message) {
$('#seo-'+field).next('div.error-message').html(message).fadeIn('fast');
});
} else {
$('#modal-spinner-seo-update').hide('slow', function() {
$("#seo-widget-message-success").fadeIn('slow').delay(2000).fadeOut('slow');
});
}
return false;
}
};
xhr.open('GET','/metas/saveMetas?model='+model+'&f_key='+f_key+'&pagetitle='+pagetitle+'&keywords='+keywords+'&description='+description+'&niceurl='+niceurl, true );
xhr.send();
and now everything seems to work fine. But I still do not understand why. Can anyone explain what I did wrong?
Hello can someone help me update the following code to 1.10.2 min jquery?
the backslash it's only cause i use it with php and i need to backslash '.
I'm not that good at javascript and i dont know what changes were made from 1.4.2 to 1.10.2
<script type="text/javascript">
$(document).ready(function(){
function loading_show(){
$(\'#loading\').html("<img src=\'images/loading.gif\'/>").fadeIn(\'fast\');
}
function loading_hide(){
$(\'#loading\').fadeOut(\'fast\');
}
function loadData(page){
loading_show();
$.ajax
({
type: "POST",
url: "pagination_photo.php",
data: "page="+page,
success: function(msg)
{
$("#photo").ajaxComplete(function(event, request, settings)
{
loading_hide();
$("#photo").html(msg);
});
}
});
}
loadData(1); // For first time page load default results
$(\'#photo .pagination li.active\').live(\'click\',function(){
var page = $(this).attr(\'p\');
loadData(page);
});
$(\'#go_btn\').live(\'click\',function(){
var page = parseInt($(\'.goto\').val());
var no_of_pages = parseInt($(\'.total\').attr(\'a\'));
if(page != 0 && page <= no_of_pages){
loadData(page);
}else{
alert(\'Enter a PAGE between 1 and \'+no_of_pages);
$(\'.goto\').val("").focus();
return false;
}
});
});
</script>
thnx in advance
Using jQuery 1.10.2 with jQuery Migrate Plugin solves the problem.
It is mentioned in jQuery Migrate Plugin read me guide. https://github.com/jquery/jquery-migrate#readme
Any deprecated feature will display warnings on the browser's console (if using plugin's uncompressed version and for IE browsers use Firebug Lite for console). In most cases these messages are simply warnings; code should continue to work properly as long as the jQuery Migrate plugin is used, but it is recommended to change the code where possible to eliminate warnings so that the plugin does not need to be used.
To find entire list of warning messages see https://github.com/jquery/jquery-migrate/blob/master/warnings.md
option.1
replace .live( with .on(
option.2
add jQuery migrate script right after jquery lib to your page
I have the following code for submitting data using ajax from forms of class ajax. this works perfectly in Firefox, Safari and Chrome but fails in IE.
ajax: function() {
$('form.ajax').live('submit', function() {
var form_ajax = $(this);
$.ajax({
url: form_ajax.attr('action'),
data: form_ajax.serialize(),
type: form_ajax.attr('method'),
dataType: 'script',
beforeSend: function(xhr) {
$('#ajax-bid-new .ajax-form-error, #ajax-bid-new .ajax-form-success').remove();
form_ajax.slideUp();
}
});
return false;
});
Please help - I am stuck here for past 2 days. I am returning a Javascript file from server to be evaluated inside browser. This works as expected in Firefox, Chrome and Safari, but IE receives it as a file and opens up the file download dialog.
What can I do in IE to make this work? I tried by dropping the following code in my application.js file (I'm doing a rails project btw)
// public/javascripts/application.js
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
I get the same behavior from IE even after writing the ajaxSetup block like above.
Looks like live doesn't work with submit in IE. Have you tried using a normal submit instead:
$('form.ajax').submit(function() {
To catch live form submit events in IE, instead of:
$("form").live("submit", function() { ... });
to
var submitHandler = function() { ... };
$("body").children().each(function() {
$("form", this).live("submit", submitHandler);
})
Point to be noted
IE caches AJAX requests really aggressively (more so than Firefox, anyway). You need to set the Cache-Control headers in the response appropriately if this is not right for your site.
change your content type, last time i fixed similar problem by changing content-type from application/json; charset=utf8 to just plain application/json
jQueries' bind and live behaviours along with the liveQuery plugin
LiveQuery plugin solved the problem http://github.com/brandonaaron/livequery
function populateGroups(){
var p =1;
var groupNames = new Array();
$.ajax({
type: "GET",
url: "http://okcmonprd103/iMon/findgroups.pl",
dataType: "text/xml",
success: function parseGroupNames(xml){
$(xml).find('group').each(function(){
groupNames[p] = $(this).find('name').text();
p++;
});
groupNames.sort(arraySort);
for(p=0;p<groupNames.length-1;p++){
$('#Groups').append('<option value="'+p+1+'">'+groupNames[p]+'</option>');
$('#dutyGroups').append('<option value="'+p+'">'+groupNames[p]+'</option>');
}
}
});
}
I send this ajax call to a server on our network that runs a Perl script that returns XML data. This works fine on my machine in IE8, and in my Windows 7 Gadget (which is what this is mainly for) but whenever other people in the company try to use it, they get the "Permission Denied" error. Do I need to set up a proxy page in order to make this work?
It does work on my machine, I just don't see how other people on the same network wouldn't be able to use this...
It turned out that it was a Windows 7 issue. When you right clicked on the HTML file name, under security, it would say something like "this file is blocked because it came from another computer"
All you had to do was press the "Unblock" button and all of a sudden it worked.