I am creating a chrome extension that goes back to a certain site. But history.go(-1);The syntax is not working Why?
chrome.tabs.executeScript({
code: 'document.URL;'
}, function (domain) {
var google = 'https://www.google.co.kr/';
if (domain == google) {
history.go(-1);
}
else
alert('not google')
$.ajax({
type: 'GET',
url: 'http://www.mhwdb.kr/main/apis/monsters',
// data: {
// url: domain
// },
// dataType: 'json',
success: function(success){
document.getElementById('url').innerHTML = success;
},
error: function(error) {
console.log(error);
}
})
})
Related
Can anyone see why this script would fail to redirect?
$.ajax({
url: url,
data: JSON.stringify(viewModel),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
cache: false,
type: "POST",
success: function (result) {
if (result.success === true) {
showFullScreenLoadMask(false);
//var redirect = "/Login/Index";
//window.location.href = getUrlPath() + redirect;
var redirecturl = getUrlPath() + "/Login/Index";
/*F5_*/ F5_Deflate_location( /*_5F##*/ window /*F5_*/ ) /*_5F#.location#*/ .assign = redirecturl;
} else {
// hide any previous errors
$("#divPasswordHistoryError").hide();
$("#divFullNameError").hide();
$("#divCurrentPasswordError").hide();
if (result.vm.ShowPreviousPasswordFail === true) {
$("#divPasswordHistoryError").show();
$("#divPasswordHistoryError").removeClass("hidden");
}
if (result.vm.ShowFullNameError === true) {
$("#divFullNameError").show();
$("#divFullNameError").removeClass("hidden");
}
if (result.vm.ShowCurrentPasswordFail === true) {
$("#divCurrentPasswordError").show();
$("#divCurrentPasswordError").removeClass("hidden");
}
$("#Username").val(result.vm.Username);
$("#Password").val(result.vm.Password);
$("#NewPassword").val("");
}
},
error: function (responseText, textStatus, errorThrown) {
alert('Error - ' + errorThrown);
}
});
Above is the code I have on my login script, but for the life of me, I cant get my head around as to why it would not be redirecting to the correct page after someone enters their password.
I have this jquery to make a post request:
$('#btnAdd').click(function (e) {
$('#modal_processing').modal('show');
$('#modal_body_process').html("Please wait while we are processing your request. This message will automatically close when request successfully completed.");
$('#modal_title_process').html("Processing...");
$.ajax({
url: '#Url.Action("AddNew", "Home")',
type: 'POST',
data: {
Name: $('#txtEmail').val(),
Project: $('#cbProject').val(),
Gender: $('#cbGender').val(),
Level: $('#cbLevel').val(),
ShiftStart: $('#txtShiftStart').val(),
ShiftEnd: $('#txtShiftEnd').val(),
GeoId: $('#cbGeo').val(),
TowerId: $('#cbTower').val(),
ProcessId: $('#cbProcess').val(),
PrimaryTeamId: $('#cbPrimaryTeam').val(),
RegionId: $('#cbRegion').val(),
WBSId: $('#cbWBS').val(),
},
dataType: "json",
success: function (response) {
$('#modal_body_process').html("New user has been successfuly added.");
$('#modal_title_process').html("Successful!");
setTimeout(function () {
$('#modal_processing').modal('hide');
}, 3000);
},
error: function (resp) {
$('#modal_body_process').html("Please fill out all required fields.");
$('#modal_title_process').html("Error");
setTimeout(function () {
$('#modal_processing').modal('hide');
}, 3000);
alert("Error");
}
});
});
in my controller, i have this:
if (result.IsSuccessStatusCode)
{
ModelState.Clear();
return Json(result.StatusCode, JsonRequestBehavior.AllowGet);
}
return View(model);
my problem is, everytime the result is success, it always prompting me to download the json file (IE 11) and for mozilla, it opens the json file.
how can i prevent this?
It won't go to a new browser tab, is my code wrong?
function getWaterMeterList() {
// alert("ON");
var BillingPeriod = $('#BillingPeriod').val();
$.ajax({
url: '/DataEntryWater/WaterMeterAlphaListReport',
type: 'POST',
data: { 'BillingPeriod': BillingPeriod },
dataType: 'json',
success: function (a) {
$(location).attr('href', a)
a.preventDefault();
},
error: function (err) {
}
});
}
What you're looking for might be:
window.open('http://stackoverflow.com/', '_blank');
And in your code:
function getWaterMeterList() {
// alert("ON");
var BillingPeriod = $('#BillingPeriod').val();
$.ajax({
url: '/DataEntryWater/WaterMeterAlphaListReport',
type: 'POST',
data: { 'BillingPeriod': BillingPeriod },
dataType: 'json',
success: function (a) {
var win = window.open('http://stackoverflow.com/', '_blank')
if(win) {
win.focus(); /if tab is open, change focus there.
}
},
error: function (err) {
// do stuff here
}
});
}
I am using AJAX to read a large JSON file (about 15 MB minified), in order to display autocomplete suggestions on a text field.
The problem is that after user types 4 characters in order the suggestions to begin, i have to wait around 20 to 60 seconds which makes actually impossible to use it.
I don't know any techniques how i could make it read the JSON file faster.
I would like to read your suggestions...
My AJAX request is :
$(document).ready(function () {
$("#card").autocomplete({
source: function (request, response) {
$.ajax({
dataType: "json",
data: {
term: request.term,
},
type: 'GET',
contentType: 'application/json; charset=utf-8',
xhrFields: {
withCredentials: true
},
cache: true,
url: base_url+'/test123/wp-content/plugins/trading-collectible-cards/public/js/AllSets.json',
success: function (data) {
var keys = Object.getOwnPropertyNames (data)
var outputArray;
$.each(keys,function(ele, val){
var array = $.map(data[val].cards, function (set) {
return {
label: set.name + " (" +data[val].name + ")",
value: set.name,
text: set.text,
multi: set.multiverseid,
rarity: set.rarity,
setname:keys[ele],
setfull:data[val].name
}
});
if (ele == 0)
outputArray = $.merge([], array);
else {
outputArray = $.merge(outputArray, array);
}
});
response($.ui.autocomplete.filter(outputArray, request.term));
},
error: function (data) {
}
});
},
minLength: 3,
open: function () {
},
close: function () {
},
focus: function (event, ui) {
},
select: function (event, ui) {
$( "#card" ).val( ui.item.label );
$( "#description" ).html( ui.item.text );
}
});
Code below works fine in IE, but onsuccess(...) method is not getting called in Chrome. Does any one know the solution?
$(document).ready(
function (e) {
$.support.cors = true;
$.ajax({
dataType: "JSON",
type: "GET",
crossDomain: true,
url: "http://localhost:36730/home/GETaaa",
success: function (data) {
//console.log(data);
alert(data);
},
Error: function (xhr, error, message) {
alert(xhr);
}
});
}
)