|
Not possible unless eash user's machine is running Node.js[^].
(or some other runtime that exposes native API hooks to the browser)
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
I wrote this from scratch, and I'm trying to get the addClass to run the font spinner before the $ajax runs; but the $ajax is so fast, that the spinner never shows.
I tried queue, which works, if I queue after changing the class. But when I try to run it a 2nd time, it runs but sort of does nothing. I destroyed my queue work and reverted back to the sample below.
Tried Delay, but that seems to only work with animation.
Tried setTimeout, but had no luck.
Just nice to have, but can live without it.
function js_add2Cart(_sku) {
var $itemQty = $("#selectQty"),
$itemType = $("#Type"),
$spinner = $("#js-add2Cart > i"),
$NavCart = $("#navCartCount"),
_qty = parseInt($itemQty.val()),
_type = $itemType.val();
if (isNaN(_qty)) { _qty = 1; }
$.ajax({
type: "POST",
cache: false,
dataType: "json",
url: '/Ajax/json_add2cart',
data: { Sku: _sku, Qty: _qty, Type: _type },
beforeSend: function () {
$spinner.addClass('fa-cog fa-spin');
$("#js-add2Cart").html('Add to Cart').removeClass('error').addClass('add2cart');
},
error: function (xhr, ajaxOptions, thrownError) {
$("#js-add2Cart").removeClass('add2cart').addClass('error').html('Error has occured');
},
success: function (data) {
$NavCart.text(data);
},
complete: function () {
$("#js-add2Cart").html('Item added');
$spinner.removeClass('fa-cog fa-spin');
}
});
}
|
|
|
|
|
How about something like this:
$("#js-add2Cart").html('Add to Cart').removeClass('error').addClass('add2cart');
$("#js-add2Cart > i").addClass('fa-cog fa-spin');
setTimeout(function(){
var _qty = parseInt($("#selectQty").val(), 10),
_type = $("#Type").val();
if (isNaN(_qty)) { _qty = 1; }
$.ajax({
type: "POST",
cache: false,
dataType: "json",
url: '/Ajax/json_add2cart',
data: { Sku: _sku, Qty: _qty, Type: _type },
error: function (xhr, ajaxOptions, thrownError) {
$("#js-add2Cart").addClass('error').html('Error has occurred');
},
success: function (data) {
$("#js-add2Cart").html('Item added');
$("#navCartCount").text(data);
},
complete: function () {
$("#js-add2Cart").removeClass('add2cart');
$("#js-add2Cart > i").removeClass('fa-cog fa-spin');
}
});
}, 900);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I never thought about wrapping the $.ajax in a setTimeout. duh!
And I wrote up this morning thinking I could of just extended the Async delay in the call to the controller as well; duh!
Yours looks more elegant and reliable.
|
|
|
|
|
Well that was strange. Implemented both thoughts, and the same thing happened.
Did some isolating and figured the line to remove was the 'error' class and add the 'add2cart' class was should be the the villain; so I wrapped it with the if statement. Now it works right.
Guess jQuery was too busy processing that request.
I know that line will come back and haunt me soon, when it's triggered.
if ($("#js-add2Cart").attr('class') === 'error') {
$("#js-add2Cart").removeClass('error').addClass('add2cart').html('Add to Cart');
}
$spinner.addClass('fa-cog fa-spin');
if (isNaN(_qty)) { _qty = 1; }
$.ajax({
type: "POST",
cache: false,
async: false,
dataType: "json",
url: '/Ajax/json_add2cart',
data: { Sku: _sku, Qty: _qty, Type: _type },
error: function (xhr, ajaxOptions, thrownError) {
$("#js-add2Cart").removeClass('add2cart').addClass('error').html('Error has occured');
},
success: function (data) {
$NavCart.text(data);
},
complete: function () {
$("#js-add2Cart").html('Item added');
$spinner.removeClass('fa-cog fa-spin');
}
});
|
|
|
|
|
jkirkerx wrote: if ($("#js-add2Cart").attr('class') === 'error') {
It would probably be better to use .hasClass()[^] there:
if ($("#js-add2Cart").hasClass('error')){
That way, it will still work even if you have any other classes on the element.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I didn't know about that call, thanks!
will make the change now.
|
|
|
|
|
As a beginner in Big Data, where do i start to build a simple project or basic project in implement Big Data?
|
|
|
|
|
|
Having just been dipped into the steaming pile of crap based on hadoop/java I found the OPs question too stunning to attempt to answer.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I encounter this issue fairly regularly at work, and I'm interested in learning about how others handle it. Basically, when you have a Web app and you make some changes to a JavaScript file, how do you ensure that the correct script is loaded when users navigate to the updated Web app? We're using ASP.NET MVC, IIS 7.
I've done some digging online and a common solution seems to be appending some sort of identifier to script files in the markup, like this:
<script src="scripts/myscript.js?v=123"></script>
Where 'v' is maybe a version number or something along those lines, updated with each deployment. I came across a StackOverflow post in which someone provided a custom HtmlHelper method to append the file's 'LastWriteTime'. But I was wondering how you all handle this.
Thanks in advance!
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
|
Ah, wonderful! Thanks! I'll read over them today or tomorrow.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
I have JSON file locally, with array of objects
[
{
"id" :1,
"movieStill": " <img src='imgsMovie/Transformer 1/StillPhoto/StillPhotoBackground.jpg'/>",
},
{
"id" :2,
"movieStill": " <img src='imgsMovie/Transformer 2/StillPhoto/StillPhotoBackground.jpg'/>",
}
]
Then, i have two html pages, one is index.html and movie.html
in index.html i am passing a GET query to the url
(movies.html?id=1)
And then in movie.html, how to grab the value of id from GET query, and show the content from that object?
Because, when i click on item with id: 1 want to show the img from object 1, with id 1, but now it shows me both imgs.
|
|
|
|
|
How do you read the JSON file and where is the code where you actually render the objects? You will have to iterate over the collection of objects and then find the one you are interested in.
Since you haven't mentioned the framework that you are using (or the vanilla JavaScript), there is very less information for me to help you out. But however, go through this: javascript - Get specific JSON object by id from JSON array in AngularJS - Stack Overflow[^] (it covers AngularJS, you can get the idea of doing this in native JavaScript using binary search algorithm).
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
Posted an answer on that thread. Close this thread, as reposting is not allowed. You should wait for a while.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
I'm attempting to create jasmine unit tests to an existing Angular web project. But I'm having real problems getting it to work. I'm not very familiar with JavaScript or Angular (far more comfortable in C#), so it could well be a noob mistake.
This is all in Visual Studio 2015 with Jasmine 2.4.1 and Angluar 1.5.8. I'm using the Chutzpah addin to run the tests.
Jasmine works with noddy tests like 2+2 = 4 , but as soon as I try to test the actual app I run into problems.
I started with something simple, testing one of the filters. But I've found 4 different approaches but they all fail with what looks to be internal issues (i.e. not the actual test).
One test is:
describe('Matterhorn 4', function()
{
describe('SortCodeFilter', function()
{
var createFilter;
beforeEach(angular.mock.module('ngRoute', []));
beforeEach(angular.mock.module('LocalStorageModule', []));
beforeEach(angular.mock.module('angular-loading-bar', []));
beforeEach(angular.mock.module('angularUtils.directives.dirPagination', []));
beforeEach(function()
{
module('MatterhornAuthApp', ['ngRoute', 'LocalStorageModule', 'angular-loading-bar', 'angularUtils.directives.dirPagination']);
inject(function($injector)
{
createFilter = $injector.get('SortCodeFilter');
});
});
it('should return stuff', function()
{
expect(createFilter('12345')).toBe('01-23-45');
});
});
});
I think I understand what this is doing, but it fails with things like
Error: [$injector:modulerr] Failed to instantiate module undefined due to:
[ng:areq] Argument 'fn' is not a function, got undefined
I think its references or dependencies, but I've ran out of files to reference at the top of the test and can't work out how you work out what the dependencies even are!
I suppose I'm used to more help or info being provided by the ide/compiler that helps lead me where to look.
|
|
|
|
|
Found that by commenting out chunks of my Angular app definition, the test then works.
Not sure why, what I assume is an issue with the Angular code, is effecting the operation of the test?
|
|
|
|
|
Anyone can help me I was wondering if it is possible to reload only content page, without reloading menu (which is on the left side of the page).
|
|
|
|
|
Absolutely. Google AJAX to learn how to get started.
And despite what some people seem to think, you can do it with just JavaScript, jQuery is not required (if you're not already using it anyway).
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Here's one place to start:
[^]
For what it's worth to you, I only use normal javaScript - never any frameworks.
Another way to load content without refreshing menu bar: read up on iframe's - put your content in one and refresh the content from your menu. Other ways exist too, (such as via DOM) depending upon where your data source is and what it is your refreshing.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
var tempDiv = "<div class = "someClass"></div>";
divs.push(tempDiv);
is this code valid in javascript?
i'm getting error in chrome console that says unexpected identifier
the error is on first line.
|
|
|
|
|
If that's the precise code you've got, and it hasn't been mangled by the site, then it's not valid Javascript. Nested quotes need to be escaped:
var tempDiv = "<div class=\"someClass\"></div>";
var tempDiv = '<div class="someClass"></div>';
You also need to remove the spaces around the = character for the string to be valid HTML.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|