PureSourceCode.com - AjaxAll technologies, only pure source codehttp://puresourcecode.com/
http://www.rssboard.org/rss-specificationBlogEngine.NET 3.3.6.0en-GBhttp://puresourcecode.com/opml.axdhttp://www.dotnetblogengine.net/syndication.axdEnrico RossiniPureSourceCode.com0.0000000.000000$.ajax No 'Access-Control-Allow-Origin' header is present on the requested resource with WebAPI<p>I want to get data from a WebAPI with jquery </p> <pre class="brush: js;"> $(&quot;#btnSend&quot;).click(function () {
$(&quot;#sending&quot;).show();
$.ajax({
type: 'GET',
url: '/Report/SendEmail?quote=18',
crossDomain: true,
success: function (msg) {
if (msg == 'True') {
alert('Email sent to the client');
}
$(&quot;#sending&quot;).hide();
},
error: function (request, status, error) {
$(&quot;#sending&quot;).hide();
}
});
});</pre>
<p>and it produce </p>
<blockquote>
<p>‘No Access-Control-Allow-Origin' header is present on the requested resource error.</p>
</blockquote>
<p>The solution is to add in the result of the WebAPI the following code:</p>
<pre class="brush: csharp;">
Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST");
Response.Headers.Add("Access-Control-Allow-Headers", "accept, authority");
Response.Headers.Add("Access-Control-Allow-Credentials", "true");
</pre>
<p>
Happy coding!
</p>http://puresourcecode.com/dotnet/dotnet/post/2016/10/06/$ajax-No-Access-Control-Allow-Origin-header-is-present-on-the-requested-resource-with-WebAPI
enrico.rossini.uk@live.comhttp://puresourcecode.com/dotnet/dotnet/post/2016/10/06/$ajax-No-Access-Control-Allow-Origin-header-is-present-on-the-requested-resource-with-WebAPI#commenthttp://puresourcecode.com/dotnet/post.aspx?id=be9519ba-343b-4d82-a036-228727304a84Thu, 6 Oct 2016 10:24:49 -0800WebAPIC#AjaxJavaScriptaccessalloworiginjqueryhenryhttp://puresourcecode.com/dotnet/pingback.axdhttp://puresourcecode.com/dotnet/post.aspx?id=be9519ba-343b-4d82-a036-228727304a840http://puresourcecode.com/dotnet/trackback.axd?id=be9519ba-343b-4d82-a036-228727304a84http://puresourcecode.com/dotnet/dotnet/post/2016/10/06/$ajax-No-Access-Control-Allow-Origin-header-is-present-on-the-requested-resource-with-WebAPI#commenthttp://puresourcecode.com/dotnet/syndication.axd?post=be9519ba-343b-4d82-a036-228727304a84Using the UpdateProgress to lock down controls in the browser<p>If it takes awhile for the server to process the postback (e.g. complex rules or badly written code ), the user may not realize that the server is processing the request. This can lead to all kinds of issues with users that are not savvy or familiar with web applications (multiple clicks, moving off the page, etc.). Consequently, I want to tell the user that the server is processing the request <em>and</em> disable the controls on the page. Let's break this down into two steps: show a message, and disable the user's interaction with the controls.</p> <p>You can use the UpdateProgress control alone with the UpdatePanel to provide a message to the user during the postback. This is very simple -- put the UpdateProgress control within the UpdatePanel like so:</p> <pre>&lt;asp:UpdateProgress ID=&quot;UpdateProgress1&quot; runat=&quot;server&quot;&gt;
&lt;ProgressTemplate&gt;
Update in progress. Please wait ...
&lt;/ProgressTemplate&gt;
&lt;/asp:UpdateProgress&gt;
&nbsp;
</pre>
<p>This will display the &quot;Update in progress. Please wait ...&quot; message to the the user while the server is processing the request. However, it doesn't prevent the user from continuing to interact with the web application. To provide this type of functionality, we will use the PageRequestManager to invoke some JavaScript while also using CSS and DHTML to lock down the UI.</p>
<p>First, we'll add a little more to our UpdateProgress control:</p>
<pre>&lt;ProgressTemplate&gt;
&lt;div id=&quot;blur&quot; /&gt;
&lt;div id=&quot;progress&quot;&gt;
Update in progress. Please wait ...
&lt;/div&gt;
&lt;/ProgressTemplate&gt;
&nbsp;
</pre>
<p>We'll use the &quot;blur&quot; and &quot;progress&quot; controls to _overlay _the controls in the UI while also providing a message to the user. To provide the functionality we require, we need to use the following CSS elements:</p>
<pre>#blur
{
width: 100%;
background-color: black;
moz-opacity: 0.5;
khtml-opacity: .5;
opacity: .5;
filter: alpha(opacity=50);
z-index: 120;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
#progress
{
z-index: 200;
background-color: White;
position: absolute;
margin-left: auto;
margin-right: auto;
border: solid 1px black;
padding: 5px 5px 5px 5px;
text-align: center;
width: 100%;
left: 0px;
height: 75px;
padding-top: 40px;
padding-bottom: 60px;
}
&nbsp;
</pre>
<p>The purpose of the &quot;blur&quot; control is to provide a tag that lays over everything in the browser. Since the opacity is 0.5 (and 50), it appears gray while allowing the user to continue to see the controls behind it. However, since the &quot;blur&quot; control exists between the user and the other controls, the user cannot interact with any other controls.</p>
<p><a href="http://puresourcecode.com/dotnet/image.axd?picture=image.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://puresourcecode.com/dotnet/image.axd?picture=image_thumb.png" width="634" height="149" /></a></p>http://puresourcecode.com/dotnet/dotnet/post/2015/06/25/Using-the-UpdateProgress-to-lock-down-controls-in-the-browser
enrico.rossini.uk@live.comhttp://puresourcecode.com/dotnet/dotnet/post/2015/06/25/Using-the-UpdateProgress-to-lock-down-controls-in-the-browser#commenthttp://puresourcecode.com/dotnet/post.aspx?id=ce004f43-b613-4880-942d-e18615c0cd37Thu, 25 Jun 2015 12:31:09 -0800JavaScriptHTMLASP.NETAjaxUpdateProgressUpdatePanelasp.netajaxhenryhttp://puresourcecode.com/dotnet/pingback.axdhttp://puresourcecode.com/dotnet/post.aspx?id=ce004f43-b613-4880-942d-e18615c0cd370http://puresourcecode.com/dotnet/trackback.axd?id=ce004f43-b613-4880-942d-e18615c0cd37http://puresourcecode.com/dotnet/dotnet/post/2015/06/25/Using-the-UpdateProgress-to-lock-down-controls-in-the-browser#commenthttp://puresourcecode.com/dotnet/syndication.axd?post=ce004f43-b613-4880-942d-e18615c0cd37