I'm trying to hack together an extra feature on top of a POC (smoke and mirrors demo). The POC is on SPS 2007 and I need to integrate with another system.
To facilitate part of this, I need to provide a JSONP endpoint.
I want this URL:
http://sharepoint:2024/Pages/SomeExternalSystem/Payload.aspx?callback=abc
To return this:
abc({ sampleField1: "sampleData1", sampleField2: 234.56 });
It's all smoke and mirrors anyway, so I uploaded this file to SharePoint:
<%# Page ContentType="text/javascript" Language="C#" %>
<%= Request.QueryString["callback"] %>({
sampleField1: "sampleData1",
sampleField2: 234.56
});
(And added a page parser rule to allow it to compile the code blocks.)
No matter what I seem to do, SharePoint emits this instead:
abc({
sampleField1: "sampleData1",
sampleField2: 234.56
});
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head>
<!--[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:PublishingContactPicture msdt:dt="string"></mso:PublishingContactPicture>
<mso:PublishingRollupImage msdt:dt="string"></mso:PublishingRollupImage>
<mso:Audience msdt:dt="string"></mso:Audience>
<mso:PublishingContactName msdt:dt="string"></mso:PublishingContactName>
<mso:ContentType msdt:dt="string">Page</mso:ContentType>
<mso:Comments msdt:dt="string"></mso:Comments>
<mso:PublishingContactEmail msdt:dt="string"></mso:PublishingContactEmail>
</mso:CustomDocumentProperties>
</xml><![endif]-->
</head>
It's proving hard to Google for.
As an extreme hack, this works:
<%# Page ContentType="text/javascript" Language="C#" %>
<%
Response.Clear();
Response.Write(Request.QueryString["callback"]);
Response.Write("({ sampleField1: \"sampleData1\", sampleField2: 234.56 });");
Response.Flush();
Response.End();
%>
Related
I created this script to hide a page only if chrome 18 has not been found, how can I make sure to do the redirect of the url to a external page if chrome 18 has not been found instead of hiding only the page ?
I want to do the redirect to this website http://search.aol.com/aol/webhome
<div id="hiddenContent" style="display: none;">
My hidden content.
</div>
<script>
function GetChromeVersion() {
var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
return raw ? parseInt(raw[2], 10) : false;
}
if (GetChromeVersion() == 18)
document.getElementById("hiddenContent").style.display = "";
</script>
It's possible, e.g. by using:
window.location.href='http://search.aol.com/aol/webhome';
Inside your function. BUT I wouldn't recommend you this. You should never trust the client as JavaScript can easily be changed and someone could access your site even despite the JavaScript redirect if they wanted to and made a minimal effort to modify page sources. Javascript is handled on the client-side, while php is completely server-side. In this case I'd use php instead of JavaScript. Try to check it with php and if it's not chrome 18, use: header('Location: http://search.aol.com/aol/webhome');
Edit:
<?php function is_chrome()
{
return(eregi("chrome/18", $_SERVER['HTTP_USER_AGENT'])); } if(is_chrome()) { header('Location: http://www.search.aol.com/aol/webhome'); } ?>
Place it on top of the file, should work, but haven't tested it yet, if not, just change the string in eregi('chrome/18') to what you need (it's a regular expression)
I am trying to consume a wcf rest api in a asp.net project using jquery. for doing so i have done:
Created a WCF Rest service source code can be downloaded from here.
Created a ASP.Net project to consume that restAPI using jquery. source code here.
In ASP .Net project on the click of button I am trying to call a REST service. But every time I gets two issues:
calling var jsondata = JSON.stringify(request); in TestHTML5.js throws an error saying "Microsoft JScript runtime error: 'JSON' is undefined"
When I press ignore it continues towards WCF Rest API call but it always returns error (Not Found) function. Rest API never gets called.
Thanks for every one's help in advance.
ANSWER:
Solution and source link can be found on this link.
I have looked at the sample code you provided and the problem is that you are violating the same origin policy restriction. You cannot perform cross domain AJAX calls. In your example the service is hosted on http://localhost:35798 and the web application calling it on http://localhost:23590 which is not possible. You will have to host both the service and the calling application in the same ASP.NET project. You seem to have attempted to enable CORS on the client side using ($.support.cors = true;) but on your service doesn't support CORS.
Another issue saw with your calling page (TestHTML5.htm) is the fact that you have included jquery twice (once the minified and once the standard version) and you have included your script (TestHTML5.js) after jquery. You should fix your script references. And yet another issue is the following line <script type="text/javascript"/> which is invalid.
So start by fixing your markup (I have removed all the CSS noise you had in your markup in order to focus on the important parts):
<!DOCTYPE html>
<html dir="ltr" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>SignUp Form</title>
<script type="text/javascript" src="../Scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../Scripts/TestHTML5.js"></script>
</head>
<body>
<button id="Send" onclick="testHTML5OnClick();">
Send Me ID!
</button>
</body>
</html>
and then in your TestHTML5.js you could also clean a little bit. For example your service is listening for the following url pattern json/{id} and accepting only GET verbs and you are attempting to use POST which is not possible. In addition to that you are attempting to use the JSON.stringify method which doesn't make any sense with the GET verb. You should simply send the id as part of the url portion as you defined in your service.
function testHTML5OnClick() {
var id = 5;
var url = "../RestServiceImpl.svc/json/" + id;
var type = 'GET';
callLoginService(url);
}
function callLoginService(url, type) {
$.ajax({
type: type,
url: url,
success: serviceSucceeded,
error: serviceFailed
});
}
function serviceSucceeded(result) {
alert(JSON.stringify(result));
}
function serviceFailed(result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
}
Did u add this reference?
script type="text/javascript" src="../../json.js"></script>
I have same problem and search i get this and this result
This issue that I'm having is not even a synchronization issue, where I'm waiting for the Ajax request to complete. I am having a problem where the ajax post doesn't even get triggered when IE is launched by WaitN. Here is my script:
$(document).ready(function () {
$("form select").change(function () {
$(this).parents().filter("form").trigger("submit");
});
$("form#theForm").submit(function (event) {
event.preventDefault();
hijack(this, UpdateList, "html");
});
function hijack(form, callback, format) {
$.ajax({
url: form.action,
type: form.method,
dataType: format,
data: $(form).serialize(),
success: callback
});
}
function UpdateList(result) {
$("#results").html(result);
}
Here is the html:
<% using (Html.BeginForm("ControllerName", "ActionName", FormMethod.Post, new { id="theForm" })) { %>
<table width="100%">
<tr>
<td align="left">
</td>
<td align="right">
Fiscal Year & Period: <%= Html.DropDownList("period", Model.FiscalPeriodSelectList)%>
</td>
</tr>
</table>
<% } %>
<div id="results">
<% Html.RenderPartial("Setup", Model.ViewModel); %>
</div>
Absolutely nothing happens when a different value is selected in the selectList. I've even left the browser open after test were done running so that I could manually change the select list. Still -- nothing happens. However, when I run the app though VS, the ajax post on the select list works perfectly. Is there something that's I'm not configuring properly?
Edit: It may be important to note that I am logging in using Basic Authentication, both when I run the mvc app manually and when NUnit is running it. After further inspection, I realized that the everything but the AJAX call back is getting executed and when I capture the AJAX error in an "alert", I being shown "Unauthorized". I am still unsure how I can fix my issue and why I'm getting Unauthorized when I run my WatiN tests from NUnit, but I'm not getting it when I use the mvc application manually.
I have noticed that I usually have a javascript error on page when running tests in Watin. I was told that is because we are not waiting for the page to load the JS file.
Do you see a JS error in the Status bar of your Browser? If so, you may want to delay the interaction your are trying to perform with Browser. That way we allow the JS file to be loaded and hopefully your issue should be resolved. Let us know how it goes. Cheers.
Can anyone help me integrate Twitter through Expression Engine. I am new to expression engine and I have tried to follow the example the Twitter Timeline developed by the EE team but couldn't get it working.
Can anyone help me with step by step process in EE2?
Thanks
Using the example from the Twitter Timeline Plugin download page, insert the following code into one of your ExpressionEngine templates:
{exp:twitter_timeline screen_name="ladygaga" limit="3"}
<div class="tweet">
<div class="date">{created_at format="%m-%d %g:%i"}</div>
<div class="author">
<div class="icon">
<img src="{profile_image_url}" width="48" height="48" alt="" />
</div>
{name}
</div>
<div class="status">{text}</div>
</div>
{/exp:twitter_timeline}
Note: The plugin only works on public Twitter feeds, so make sure that the feed your trying to display is not private. For this example, I'm using Lady Gaga's twitter stream.
All error messages are logged in the Template Parsing Log.
Therefore if you have no output, or unexpected output, enable the Template Parsing Log in the Control Panel's Output and Debugging Preferences at: CP Home > Admin > System Administration > Output and Debugging.
Reload the page in your browser and look through the Template Parsing Log for information from the Twitter Timeline:
If you still can't get the Twitter Timeline plugin to work, post a description of your problem to the ExpressionEngine 2 Technical Support Forum — they'll be able to better help troubleshoot your issue.
I have an ajax link in my application:
<head>
<script type="text/javascript">function GoFurther() { ... }</script>
</head>
...
<%= Ajax.ActionLink("Go", "SomeAction", "SomeController", new AjaxOptions() { UpdateTargetId = "someDiv" }) %>
<div id="someDiv"></div>
I want to execute GoFurther() after ajax request completes AND someDiv is filled with its content so that it can bind some events on some buttons that've come from server. OnCompleted and OnSuccess seem to work after the ajax answer is received but before someDiv is filled. So they do not work for me.
To be clear, some div will be filled with some content after ajax call:
<someDiv><input type="button" value="Click" class="someButton" /></someDiv>
GoFurther makes some bindings using $(".someButton").click(...); so it must run once someDiv is completely filled. How can I make sure it runs after someDiv is filled?
OnSuccess is supposed to run after the DOM element has been updated [according to the source code for the Mvc Ajax Helpers - see OnComplete method]. Is there a particular problem that is occurring when you use OnSuccess?