I am trying to call the WCF service from Jquery. But if I replace the url with my machine name it doesn't work. The html/jquery and WCF are both on the same web site (project). I think many people need help with this since there is no way to debug and figure out the problem. Instead of continuously changing the wcf service file, web.config file and html (ajax function) page, does anyone have a running project with this issue?
$.ajax({
type: "POST",
//work well
//url: "Service1.svc/MyFunction",
//work well
//url: "http://localhost:43969/Service1.svc/MyFunction",
//not work ???
//url: "http://PWLL-IT-056:43969/Service1.svc/MyFunction",
data: '{"Count": "' + counter + '"}',
contentType: "application/json", // content type sent to server
success: ServiceSucceeded,
error: ServiceFailed
});
Thanks for help guys,
Related
i am trying to call php rest webservice from MVC ajax but after calling it it is not going to call success i dont what i am missing here.
webservice required 2 paramaters my code
$.ajax({
type: "POST",
url: "https://test.com/custom/",
dataType: "json",
contentType: "application/json",
data: { "ReleaseVersion": "XXX", "ReleaseType":"XXX" },
success: function (data) {
alert("webservice called successfully");
}
})
it tried using json.stringfy while passing parameters but it wont work.
is anyone how to solve this.
Environment: Visual Studio 2013 and MVC 4.0.
set datatype in ajax call that is jsonp for calling cross domain webservice.
In php webservice code you have to add header before passing json.
as header content type=application/json, then and then only you will get json from php webservice in your ajax call.
I am using the below code to let a user Follow another Instagram user. However, even though the result returns a positive success (meta.code==200), the API is still not allowing a follow.
I now understand that this is because JSONP is using script tags and GET. Is the solution to set up a proxy server? If so, can you demonstrate the code on how to do this?
Many thanks!
$.ajax({
type: "POST",
"method": "POST",
url: 'https://api.instagram.com/v1/users/' + followID + '/relationship?access_token=' + accessToken + '&callback=callbackFunction',
data: {action: 'follow'},/*need this to access the relationship*/
dataType: "jsonp",
success: function(result){
if (result.meta.code == 200) {
document.getElementById(followID).innerHTML = "Requested";
document.getElementById(followID).style.display = "none";
document.getElementById("reqID" + followID).style.display = "block";
alert(result.data.outgoing_status;);
}
}
});
There are the security risks in exposing user access token in javascript
What are the security risks in exposing facebook user access token in javascript?
The access token is a sensible data that must be always invisible.
You should do that through server side (Like PHP, ASP, JSP......)
This is a PHP wrapper for the Instagram API, it may help you
https://github.com/cosenary/Instagram-PHP-API
I've got everything working up until Step 2 of the OAuth process where you request the actual token. I'm using a very simple jQuery Post request and constantly getting Access Control Origin errors. I've tried contentType: 'application/json' and everything else I know to try.
It's just not working and I'm not sure the problem. I've confirmed all the variables are set properly before the request. Simple post request...
var url = 'https://[STORENAMEVARIABLE].myshopify.com/admin/oauth/access_token';
var data = JSON.stringify({ client_id: apiKey, client_secret: secret, code: code });
$.ajax({
type: 'POST',
url: url,
data: data,
success: function(data) {
debugger;
},
error: function(data) {
debugger;
}
});
Any ideas what I'm doing wrong?
You need to make your OAuth requests from a server. This is the Javascript cross-domain security kicking in.
If you are using Rails you can use omniAuth and it'll take care of the whole OAuth dance for you. Otherwise you'll have to search around but most popular language have an OAuth library that you can just plug in.
How can i make a cross domain POST call for a rails 3 rest service.
I have read a lot about jsonp but its only for GET method. Are there any other way to do it on rails 3. Can anybody provide me with the exact steps to make a cross domain json POST call to rails rest service.
I want to make a POST call through ajax jquery to rails server side rest service.
I tried using JSONP but it didn't work for me
Include POST as the type.
$.ajax({
type: "POST",
url: 'ruby/file/name',
data: {'foo': 'bar'},
success: function(s) {
console.log('success' + s);
},
error: function(e) {
console.log('error' + e);
}
});
My application's HTML5, jQuery Mobile frontend talks to Java server (Spring, Hibernate, MySQL). The application works fine on my notebook as well as in QA environment. On QA, I'm accessing the application using the server's IP address.
When I host the application in Live environment (the same server as QA but a different web app in Tomcat) and try to access it using URL with the domain name, $.ajax calls in the application return error.
One of the calls is as follows:
$.ajax({
type : "GET",
url : "http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi/rest/resource/getResourceTypes",
cache : false,
async : false,
dataType : 'json',
success : function(rTypes) {
Alert("success!");
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert("An error has occurred making the request: " + errorThrown);
}
});
I get the following error in Firefox:
An error has occurred making the request: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://www.smartcloudlearning.mobi/js/jquery-1.7.1.min.js :: <TOP_LEVEL> :: line 4" data: no]
I get the following error in Chrome:
An error has occurred making the request: Error: NETWORK_ERR: XMLHttpRequest: Exception 101
In the server log, I see that the requested Spring service was successfully invoked but it looks like the client doesn't receive the data!
If I hit the URL
http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi/rest/resource/getResourceTypes
directly in the browser, I get expected results! I sense that this is somehow due to how I forward server request from Apache to Tomcat.
The following are the lines in Apache / httpd server's httpd.conf file:
ProxyPass /SmartCloudLearningMobi http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi
ProxyPassReverse /SmartCloudLearningMobi http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi
Can anyone tell me what's amiss here? Much appreciated!
I managed to solve the problem:
The browser was giving the error on .ajax call because I had port number in my URL. The port number got carried over when I created 'live' URL from my QA URL. When I removed the port number from the .ajax call's URL, the call started returning success!
Jason Foglia, your statement "... and also the port..." nudged me to explore that angle... thanks a lot!
You're probably getting an error because of a security concept called "same origin policy" which doesn't allow you to call a service from a different domain. Or at least, disallow you from calling a method in that service.
Same discussion is found here - AJAX Cross Domain
You can however implement a cross-domain using JSONP - Wikipedia on JSONP
The solution is to change the datatype to JSONP:
$.ajax({
url:"http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi...",
dataType: 'jsonp',
...
});
Try using an relative url:
If that doesn't work is the domain name the same as the url and also the port.
Browsers don't allow cross domains.
$.ajax({
type : "GET",
url : "/SmartCloudLearningMobi/rest/resource/getResourceTypes",
cache : false,
async : false,
contentType : "application/json"
dataType : 'json',
success : function(rTypes) {
Alert("success!);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert("An error has occurred making the request: " + errorThrown);
}
});
The browser was giving the error on .ajax call because I had port number in my URL. The port number got carried over when I created 'live' URL from my QA URL. When I removed the port number from the .ajax call's URL, the call started returning success!
Jason Foglia, your statement "... and also the port..." nudged me to explore that angle... thanks a lot!