Have been following examples of calling a web service (GET request), and changing it slightly pointing it to my own service. The issue is that kendo appends a callback to the request address in the form of
...?callback=jQuery1910806812594877556_1375342185702&_=1375342185703
the web service fails to respond with an invalid arguments error, the issue being the & (ampersand). If you remove it, the service returns a response.
Is it possible to change the callback format on the kendo side to exclude it?
This _=1375342185703 is appended by jQuery.ajax which the Kendo DataSource uses under the hood. That thing is used as a cache buster (prevents browser caching). The fix is simple - disable jQuery caching:
transport: {
read: {
url: "your service",
dataType: "jsonp",
cache: true // enable caching which disables the cache buster
}
}
Related
In a Chrome warning, it says:
Specify SameSite=None and Secure if the cookie should be sent in cross-site requests. This enables third-party use.
How do I do this correctly using express-session?
app.use(
cors({
credentials: true,
origin: ["http://localhost:3000", "https://elated-jackson-28b73e.netlify.app"] //Swap this with the client url
})
);
var sess = {
secret: 'keyboard cat',
cookie: {}
}
if (app.get('env') === 'production') {
app.set('trust proxy', 1) // trust first proxy
sess.cookie.secure = true // serve secure cookies
sess.cookie.sameSite = 'none'
}
app.use(session(sess))
you are getting this because you are using a resource from another site and that server is attempting to set a "cookie" but, it does not have the SameSite attribute set, which is being reported in newer versions of browsers.
this (may) also be shown if you are trying to access the server page from local computer (xampp), which generally doesn't has SSL installed;
set the header line in your server page (if in PHP) as below:
header("Set-Cookie: cross-site-cookie=whatever; SameSite=None; Secure");
(remember: this must be solved from the server side.)
i got the same issue when run my code in localhost. The affected resource is _ga, _gid, _utma, _utmz. All of them from unpkg.com
and i got marker image leaflet failed request but doesnt affect the page.
since i dont understand what the specific problem so i just delete the affected resource cookies in inspect element and the code will run without notif again.
thought i know if it's better to not answer based by personal experience. just tell me if it's not help at all.
If you are using Google login button or any other identity service add this:
<GoogleLogin onSuccess={() =>()} onError={() => ()} cookiePolicy='single-host-origin'/>
I have a SOAP webservice and details of the service provided are: webservice name: "xyz", username: "Ashish", class name: "Initializer" and method name: "Fetchvalue". I have to call the method "Fetchvalue" in which an object of class "Initializer" is used as a paramter. I am developing a web app using SAP UI5, i tried a lot to call this method but not able to get a proper solution for this. Will you please tell me how can i call this method with specific requiremenst resulting in desired output from the webservice.
It would be possible to call a SOAP method from a UI5 application, but there are no specific UI5 components to help you with that. This means that you'll just have to make do with the lower level function, either provided by jQuery or by calling XMLHttpRequest directly.
jQuery has a specific soap plugin for this purpose, that makes calling SOAP methods quite easy:
$.soap({
url: 'http://my.server.com/soapservices/',
method: 'helloWorld',
data: {
name: 'Ashish Jain',
msg: 'Hi!'
},
success: function (soapResponse) {
// do stuff with soapResponse
},
error: function (SOAPResponse) {
// show error
}
});
Please note that the eventual call is made using XMLHttpRequest, which requires CORS headers to be setup on the server hosting your SOAP service. Alternatively, you could setup a proxy on the server that is hosting your UI5 app, that links to the server hosting the SOAP service. If you go this path, you may also want to see if you could have this proxy layer to translate SOAP into JSON for you. That would allow you to easily use a JSONModel from your UI5 app, which makes things easier and cleaner at the UI side.
Since you mentioned that you'll have to call the SOAP service using a username and password, I think a word of caution is mandatory in this answer. UI5 apps run in the browser of your end-user. This means that your end-user can have a look at your Javascript code. Hence, having a username and password in your Javascript code is bad practice. You may want to see if you can push authentication to the SOAP end-point to the proxy if possible.
Accessing web service in HTML pages, i have a static site i want to access one web service in that site.
If you are running a static site I assume that the webservice you want to access is not on the same domain and you cannot set up a proxy on the server side. If both assumptions are correct you cannot use "ordinary" ajax because of the same origin policy in the browser. Your best bet may be JSONP as it is supported by many webservices.
I will give you a simple example. To retrieve a value stored under the key "mykey" from the openkeyval storage webservice in JavaScript with jQuery, call
$.ajax({
url: "http://api.openkeyval.org/mykey",
dataType: "jsonp",
success: function(data){
// do something with data
}
});
and to store a value, call
$.ajax({
url: "http://api.openkeyval.org/store/",
data: "mykey=myvalue",
dataType: "jsonp",
success: function(data){
// your value has been succesfully saved
}
});
Please note that nowadays many people consider Cross-origin resource sharing (CORS) a better alternative to JSONP. However, it may be a bit harder to get started for you.
Try Javascript, here is sample code
<html>
<head>
<title>Hello World</title>
<script language="JavaScript">
function InitializeService(){
service.useService(http://localhost/MyWebService.asmx?wsdl, "HelloWorldService");
service.HelloWorldService.callService("HelloWorld");
}
function ShowResult(){
alert(event.result.value);
}
</script>
</head>
<body onload="InitializeService()" id="service"
onresult="ShowResult()"> </body>
</html>
I agree with the answer provided by benedolph, but thought I might add ideas that go against his assumptions.
These steps may be more complex than you'd like, but really not terribly complicated - and would be cheap, if not free. But set aside at least one full day...
1) If you don't have one, get a domain to proxy the multiple services. Either free or as little as 5 USD per month (depending on your needs).
2) Write your proxy. This can be done in the language of your choice - Java (recommend Play framework), PHP (recommend CodeIgniter framework), Javascript (Node), Ruby (Rails), etc. What you'll do (from a high level) might look like:
- Read request. This would be a url you configure on the server app.
The url might look something like, "http://yourdomain.net/get/mashup/{service1:yourfirstservice.com, service2:yournextservice.com,...}.
- Parse the json into individual requests and load each of them from your server app. (The fastest way that I've found to complete this task is by using cURL's multi_init and multi_exec functions, via PHP. That said, Java and Ruby have equally powerful multi-threading capabilities).
- Put the results of each query into a json map.
- Once all responses come back, output the json response from your server and consume on your client side.
Anyway, that's what I'd do. Hope my response helps in one way or another!
-Brandon
Its so possible but you'll need some jquery, javascript, ajax for it
You can also use Jquery but the web service that you are accessing must reside on the same domain as the jQuery script that is making the request.It must comply the same domain policy.
$(document).ready(function() {
$('#Save').click(function() {
$.ajax({
url: "mydomain.com/test/ws/getData",
type: "POST",
dataType: "json",
data: "{BizName:'" + BizName + "'}",
contentType: "application/json; charset=utf-8",
success: function(msg) {
$('#status').html('Id: '+msg['d']['Id']);
},
error: function(e) {
$('#status').innerHTML = "Unavailable";
}
});
});
);
I'm trying to call a local webservice/webApi using jquery, but I have been stuck for days. could somebody help me please.
So my webservice is sitting on localhost port 4011 i.e. localhost:4011/api/poi/
And my javascript is sitting on local host port localhost:4213/ and here is how I call it:
$.get('http://localhost:4011/api/values', function (data) {
alert(data);
});
When I enter the url into the browser directly, it returned the result. But when I'm calling it using the jquery. I have no response (by looking from the developer tools).
I'm not sure what I'm doing wrong. Please help.
I'm using webApi mvc .net4 if that helps.
This is due to the Same origin policy. Because the API is on a different port to where you're serving the web page the browser will not allow you to make the request.
You can use jsonp to get around this, or by using cross origin policy on your web service.
Use this if you are using a CrossDomain as CrossDomain doesn't work in jQuery!
$.ajax({
url: 'ajax/test.html',
crossDomain: true,
success: function(data) {
alert(data);
}
});
you might be restricted by the cross origin policy CORS. Configure your web service to accept the requests made from across the domain. You can add Access-Control-Allow-Origin headers like
responseMessage.Headers.Add("Access-Control-Allow-Origin","*");
I'm running Sitecore 6.4 and trying to get some data using ajax and webmethod in Sitecore. Everything is in a sublayout (user control)
This is the code that calls the webmethod:
$("#NextBanner").click(function () {
$.ajax({
type: "POST",
url: "/GetNext",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('success');
},
error: function (err) {
alert('error');
}
});
This is the webmethod, returns a string:
[WebMethod]
public static string GetNext()
{
return "Hello";
}
In a test project without using Sitecore I used "Default.aspx/GetNext" as the url for the ajax call but now obviously this doesn't work, I get 404 not found error because of the url.
What should the url be? The sublayout path is: /layouts/sublayouts/test.ascx
Any recommendation on a different approach of achieving this?
Thanks,
T
Update
Thanks everybody for the answers.
I ended up creating a web service under website/sitecore/shell/webservices, not sure if that's the right place to put the web service, any suggestions?
Thanks,
T
Put the code in a WebForm. You can't call a sublayout like a page. Reference the file by its file system path in your ajax call, e.g. /layouts/ajaxProcessor.aspx
You should also check out the following blog post about sitecore and ajax goodness: http://blog.velir.com/index.php/2011/09/22/lazy-websites/
Instead of using web methods, we'll typically make use of ASP.NET MVC controllers to serve JSON data in Sitecore projects. Properly setup, you can access some Sitecore.Context values (just not Item) and all Sitecore data access APIs.
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/10/Sitecore-MVC-Crash-Course.aspx
http://shashankshetty.wordpress.com/2009/03/04/using-jsonresult-with-jquery-in-aspnet-mvc/
The Json() ActionResult option in MVC controllers makes sending back serialized data really easy.
I created a folder under 'Website' and placed my web services there.