Архиви на категоријата: JavaScript

HTTP 406 Грешка Кога Користејќи аголна $ http.get против SharePoint ОДМОР крајни точки

Ажурирање: Marc AD ndersson pointed out this great piece of info: HTTP://blogs.office.com/2014/08/13/json-light-support-rest-sharepoint-api-released/. That explains a lot :).

That may be the worst title of a blog post ever! Anyhoo.

I typically do all of my prototyping against an O365 instance. I have my personal instance so that I don’t have to be worried about affecting anyone else. As an aside – remember when we call carried around virtual machines on our laptops with MOSS – SQL Server, IIS, deciding Hyper-V vs. VMWare? Anyhoo…

I had developed an app using Angular in this environment that does, меѓу другото, овој:

$http.get(serverUrl)
.success(функција(податоци, статус, headers, конфигурациски) {

var getLinksResponse = data;

getLinksResponse.value.forEach(функција(theResult) {

// and so on and so froth

This was working just fine in two different SharePoint online environments. Сепак, when my colleague ported it to a Cloudshare instance, he was getting an HTTP 406 грешка (which was the first time I ever got that one, so … yay, I guess). We did a bit of research and noticed that the “Accept” header was off. SharePoint online was perfectly happy with:

Accept: application/json

But the cloudshare instance (which is SP on prem, hosted in a virtual server) wanted the classic “odata=verbose” added in as well:

Accept: application/json;odata=verbose

To fix that, we added the header as such:

var config = {headers: {
‘Accept’: ‘application/json;odata=verbose’
}
};

$http.get(serverUrl,конфигурациски)
.success(функција(податоци, статус, headers, конфигурациски) {

var getLinksResponse = data;

getLinksResponse.value.forEach(функција(theResult) {

// and so on and so froth

That got rid of the 406, but it also changed the format of the response. It was more … verbose. (haha!) More changes were required and here’s the final result:

var config = {headers: {
‘Accept’: ‘application/json;odata=verbose’
}
};

$http.get(serverUrl,конфигурациски)
.success(функција(податоци, статус, headers, конфигурациски) {

var getLinksResponse = data;

getLinksResponse.d.results.forEach(функција(theResult) {

// and so on and so froth

This only turned into a 30 minute problem for us, so we lucked out. Hopefully someone finds this useful.

</крајот>

Аголна не успеа да bootstrap во IE9

I’ve been playing around with Angular.js for the last long while and for the life of me, I could NOT get my Angular apps to launch in IE9.  They all work fine in IE11 but IE9 would just show the curly braces and similar bits.

I searched around and couldn’t find anyone complaining about his problem.  It worked fine in Chrome, IE11, just not IE9.

I was thrown off by the fact that the IE console was giving me errors like this:

SEC7111: HTTPS security is compromised by res://ieframe.dll/forbidframing.htm

That error had me thinking there was some problem downloading the angular or other libraries that I needed.  Како што се испоставува, this was not the issue.

By poking around the internets, I finally found out that the phrase I needed to search for was “bootstrap” and that it seemed like the bootstrapping was failing.  На крајот, my problem was that I had decorated my <html> tag with the ng-app attribute, како и во:

<html ng-app="MatrixApp">

И, that didn’t work for IE9.  Наместо, I wrapped all the rest of the HTML in the <тело> inside a div and references MatrixApp that way.

Problem solved.

Hopefully this saves someone some grief.

</крајот>

Расте свеста / Усвојување на вклучите Javascript-рамка

Мојот колега, Javed Ansari (http://www.bigapplesharepoint.com/team?showExpertName=Javed%20Ansari&rsource=pgblog), wrote a short summary blog post on frameworks he likes or at least has been using with with SharePoint: http://www.bigapplesharepoint.com/pages/View-An-Insight.aspx?BlogID=53&rsource=PGBlog).

jQuery seems to have been the victor on the field, so to speak, for years now, but the others are more new and stills sort of battling it, like Angular. (SPServices, се разбира, has been a life saver for years and will continue to be so I think).

What are people using? Are they focused more on Microsoft’s tooling (CSOM / JSOM) or moving more toward Angular, Knockout, Ember, итн?

I have a growing bias toward these non-Microsoft frameworks. I think the MSFT stuff is harder and harder to work with, requiring almost as much of learning curve as old-style server-side dev.

Post a comment here or over at Big Apple SharePoint if you want to discuss (Big Apple will have more likelihood of a good discussion).

</крајот>

Надминат проблем досадни со Релативна Url адреси во SharePoint Брзи Стартување

I wanted to add a link to the quick launch navigation the other day and SharePoint told me:

image

Pure text version of that is:

Ensure that the URL is valid and begins with either a valid character (a number sign (#) or forward slash (/)) or a valid supported protocol (на пример, ‘http://", ‘https://", ‘file://", ‘ftp://", ‘mailto:", 'Вести:").

"Лим и сипаници!" Реков.

А за да се заобиколи ова е да се користи JavaScript за да најде познат алка во брзо стартување и замени своето однесување.

Да ги тестираат оваа, додадете нов линк до вашиот сајт тест thusly:

image

Јас се користи jQuery. To solve it, добијат некои JavaScript и jQuery врз страница користење на вашите омилени техника и со линија на кодот се допаѓа ова:

 

$(документ).подготвени( функција () {

    $("на:содржи("Тест URL заменувачки)").кликнете(функција () { alert("променето однесување клик!"); се врати лажни;});

});

И вашиот чичко Боб.

На менувачот jQuery наоѓа секој <на> ознака дека има "Тест URL замена" во своето име. Вие може да сакате да се најде мелодија дека во зависност од вашата врска и како.

На .Кликнете(функција() поголем ефект што и SharePoint би направиле кога корисникот ќе кликне. Осигурете "return false", или на друго место ќе го направи вашиот работи и потоа обидете се да го href нешто премногу, што не е речиси сигурно вашата цел.

Ова беше направено и тест во онлајн средина SharePoint но треба да работат добро во 2010 и порано премногу.

</крајот>

undefinedДа се ​​претплатите на мојот блог.

Следете ме на Twitter во http://www.twitter.com/pagalvin

Кеширање сиромашен човек во вклучите Javascript-

[TL;DR version: use cookies to store the results of async calls; render the results of past async calls immediately and then validate them after page-load.]

I’ve been working on SharePoint intranet site for a client that features, меѓу другото, a stylized secondary navigation whose menu options are managed via a regular old custom list.  The idea is that the client gets to control “their” site’s menu without affecting or being affected by the global navigation put out by IT.

(there is something incredibly subversive about adding a CEWP that points to an HTML file that loads some CSS and JS to fundamentally alter almost everything about a site’s behavior… but that’s for another post)

The code for this pretty simple:

The sore spot here is that every time anyone hits one of the site’s pages, that user’s web browser is reaching out to get items from the list.  Once dev is complete and testing has proven things to be stable and complete, this call is unnecessary more than 99% of the time since the menu rarely changes.  It also has a weird UI affect which is common in this brave new world of hyper-ajaxy web sites – the page renders and only then does the menu render.  It’s jittery and distracting in my view.  And jittery. Така, caching. 

I modified the logic thusly:

  • Look for a cookie in the browser that contains the menu as I last read it
    • If found, render it immediately.  Don’t wait for the page to finish loading.  (You need to make sure your HTML is strategically placed here, but it’s not hard to do).
  • Wait for the page to finish loading and make an async call to load up menu items from a list using REST or lists.asmx or whatever
  • Compare what I got against the cookie
    • If it matches, STOP
    • Во спротивно, using jQuery, dynamically populate a bunch if <Ли>’s in a <Улица>
  • Use CSS to do all the formatting
  • Profit!

Some of you are going to say, “hey! there’s no real caching going on here since you’re reading the menu anyway every single time."  And you’re right – I’m not giving the server any kind of break.  But because the call is async and happens after the page’s initial HTML payload fully renders, it “feels” more responsive to the user.  The menu renders pretty much as the page draws.  If the menu happens to the change, the user is subjected to a jittery re-draw of the menu, but only that one time.

There are some ways to make this caching more effective and help out the server at the same time:

  • Put in a rule that the “cookie cache” is valid for a minimum of 24 hours or some other timeframe. As long as there is no expired cookie, use the cookie’s menu snapshot and never hit the server.

Well … that’s all that come to mind right now :). 

If anyone has any clever ideas here I’d love to know them.

And lastly – this technique can be used for other stuff.  This client’s page has a number of data-driven things on various pages, many of them changing relatively rarely (like once a week or once a month).  If you target specific areas of functionality, you can give a more responsive UI by pulling content from the local cookie store and rendering immediately.  It feels faster to the user even if you’re not saving the server any cycles.  Можете може save the server cycles by deciding on some conditions and triggers to invalidate this local cookie cache.  That’s all situational and artsy stuff and really the most fun :). 

</крајот>

undefinedДа се ​​претплатите на мојот блог.

Следете ме на Twitter во http://www.twitter.com/pagalvin