I started the server in Rstudio using servr::httd().
I hope to learn how to post data to R and back and I found the below.
(jQuery jsonrpc 2.0 call via .ajax() gets correct response but does not work?)
I implemented the below codes on index.html and it looked fine.
However, I am unsure what I should code to implement the server side in Rstudio.
The server codes from above URL is for python, and I have been reading for a few days without finding the way how Rstudio should be done. Please help.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({
url: 'http://localhost:4321/',
data: JSON.stringify ({jsonrpc:'2.0',method:'add', params:[1400,2100],id:"jsonrpc"} ),
type:"POST",
dataType:"json",
success: function (data) { alert("The result is : " + data.result);},
error: function (err) { alert ("Error");}
});
});
</script>
</head>
<body>
<h1> jQuery JSON RPC 2.0 demo </h1>
</body>
</html>
Related
I am using http://instafeedjs.com/ to display Instagram feed in my WordPress site.
I have included this file:
<script type="text/javascript" src="path/to/instafeed.min.js"></script>
<script type="text/javascript">
var feed = new Instafeed({
get: 'tagged',
tagName: 'awesome',
clientId: 'YOUR_CLIENT_ID'
});
feed.run();
and added into the page <div id="instafeed"></div>. But this displays
ReferenceError: Instafeed is not defined
error in the Firebug, and the feed not displays.
Does anyone know solutions to fix this?
Try to wrapp your code in some delay function, like this:
<script type="text/javascript">
jQuery(document).ready(function(){
var feed = new Instafeed({
get: 'tagged',
tagName: 'awesome',
clientId: 'YOUR_CLIENT_ID'
});
feed.run();
});
</script>
You called your instafeed.min.js after your code, thats why you get Not Defined error.
Another solution will be to call instafeed.min.js file before your code in Dom: in header, in body, up to your code. In this case you can use your code without wrapping in delay functions
I registered my project and generated a browser key at https://code.google.com/apis/console/.
Now how do I use that key when using the Google Script Loader?
I've been doing this, which works (with or without the key parameter), but even after several weeks the API console shows no requests:
<script src=//www.google.com/jsapi?key=my_key"></script>
<script>
google.load('maps', '3.10', { other_params : 'libraries=places&sensor=false', callback : ... })
</script>
The key is useless for the jsapi, you must append it to other_params:
<script>
google.load('maps', '3', {
other_params: 'key=my_key',
callback: function(){}
});
</script>
When using charts/loader you have to do something like this:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {
'packages':['geochart'],
// Note: you will need to get a mapsApiKey for your project.
// See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
'mapsApiKey': 'AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY'
});
google.charts.setOnLoadCallback(drawRegionsMap);
...
</script>
Note the mapsApiKey property.
As described in https://developers.google.com/chart/interactive/docs/gallery/geochart
Timepicker is not working in response coming from ajax request.
Same Timepicker is working fine when i run Remark.aspx page individually.
It's not working only after binding ajax response in a div in popup.
Below is the jquery reequest:-
$.ajax({
type: "POST",
url: "LMS/**Remark.aspx**",
data: {id:id, n:n},
cache:false,
success: function(response) {
$('#<%=content.ClientID %>').html(response);
},
error: function() {
alert('Some problem has been occured.');
}
});
Below is the div(this div is opening in popup) in which i am binding response:-
<div id="content" runat="server">
</div>
And if i m not opening popup it is working fine.Problem is with popup only.
Below is the timepicker which i m using:-
http://www.codeproject.com/Articles/213311/Time-Picker-Ajax-Extender-Control
Any Help would be appreciated.
Thanks.
This timepicker will auto add a js block to initialize the timePicker. You can view page source to see that.
<script type="text/javascript">
//<![CDATA[
Sys.Application.add_init(function() {
$create(Ajaxified.TimePicker, {"CloseOnSelection":true,"CssClass":"timepicker","HeaderCssClass":"header","ItemCssClass":"item","MinuteStep":15,"SelectedItemCssClass":"selecteditem","SelectedTabCssClass":"selectedtab","TabCssClass":"tab","TitleCssClass":"title"}, null, null, $get("TextBox2"));
});
//]]>
</script>
</form>
When get page content via ajax, below code is not triggered so the timepicker is not init correctly. Here you need to manually invoke your code "$(create(....." in your ajax success call back.
Always i get the alert in the "error". When i debugged i get the type,url as undefined. can anyone help me why that method is not getting called??
$(document).ready(function () {
$("#btnajaxcall").click(function () {
$.ajax({
type: "POST",
url: "Default.aspx/jQueryAjaxCalledMethod",
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: 'json',
success: function () { alert('success') },
error: function () { debugger; alert('failure'); return false; }
});
});
});
[WebMethod]
public void jQueryAjaxCalledMethod()
{
//SOME CODE HERE
}
If im correct you should be using static method for these purposes, so function in your code behind should look like this
[WebMethod]
public static void jQueryAjaxCalledMethod()
{
//SOME CODE HERE
}
If you still get some errors take a look on this guy blog Encosia maybe you'll find there a solution
The jquery Ajax method is going to post your data in json format using the plain html protocol. ASP.NET will be expecting to unwrap a SOAP request to pass to the webmethod. Thus the error. You should use an MVC action instead, as suggested in one of the comments.
EDIT:On further investigation ASP.Net has an attribute that will allow the web method to be called:
[System.Web.Script.Services.ScriptService].
Use this attribute on the class and it might solve your problem.
Hi all i just used the jquery file hosted with google.
It worked out fine.
Previously i was using the jquery version 1.7.1 that i had downloaded and stored in my local. I also saw a lot of questions in the forum that this particular ajax call is quite not happening properly with .NET 4. I am not sure and forgive me if i am wrong but i do have a feeling that 1.7.1 in this case is not properly working with ASP.NET 4.
P.S -> I used this in the script tag -->
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
What i am trying to do is basically run a script and post data to a page but the page is not on the server. So i dont want to run a redirect, just run a webpage in the back when the user clicks on a button?
I have tried...
set httpRequest = CreateObject("WinHttp.WinHttprequest.5.1")
Dim var1
var1 = Request("username")
on error resume next
httpRequest.Open "POST", "http://www.example.com", True
httpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.send var1
set httpRequest = nothing
But this doesnt seem to work. So i want to built the url http://www.example.com?username and run it?
The easiest way is to include a reference to the jQuery script libraries and use
.ajax
http://api.jquery.com/jQuery.ajax/
a call is simply:
<html>
<head>
<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" ></script>
</head>
<body>
bip
<div id="result"> results to get replaced here</div>
<div id="msg" style="color:Red">any errors will show here</div>
<input type="button" value="click me" id="loadButton" />
<script language="javascript" type="text/javascript">
//ensure jQuery is loaded before calling script
$(document).ready(function () {
alert('ready');
$('#loadButton').click(function () {
alert('Handler for .click() called.');
$.ajax({
url: 'yoursite/yourpage',
error: function (xhr, ajaxOptions, thrownError) {
alert('doh an error occured. look at the error div above : )');
$('#msg').html(xhr.status + ' ' + thrownError); ;
},
data: "{'someparam':'someparamvalue','someparam2':'someparamvalue2'}",
success: function (data) {
$('#result').html(data);
alert('Load was performed.');
}
});
});
});
</script>
</body>
</html>
Your problem is most likely this line:
httpRequest.Open "POST", "http://www.example.com", True
Your "True" there is saying run in asynchronous mode, i.e. don't wait for the response before carrying on. You are then destroying the object immediately so the request is never going to get very far. Change that "True" to a "False" and you should see the result hit the other server.
Edit 1:
Also noticed you are not formatting the POST data correctly, it should take the traditional url formatted foo=bar, so the send line needs to be modified like so:
httpRequest.send "name=" & var1
Sorry I didn't spot this first time!
Edit 2:
Here is an example of a working GET transaction with WinHttpRequest:
Function GetHTTP(strURL)
Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
objWinHttp.Open "GET", strURL, False
objWinHttp.Send
GetHTTP = objWinHttp.ResponseText
Set objWinHttp = Nothing
End Function
If you do really just need a GET transaction, you can use the following with this function:
strResponse = GetHTTP("http://www.example.com/?name=" & Request("username"))
And as you don't need the response, just ignore strResponse from there on in.
Reference:
NeilStuff.com - Open Method