I am trying to get the data from neo4j database which is at a remote location for which I make a ajax request which is as follows:
$.ajax({
type: "POST",
// headers: {"Access-Control-Allow-Origin": "*"},
url: "http://<mysite>.sb04.stations.graphenedb.com:24789/browser/",
headers: {
"Authorization": "Basic " + btoa('email' + ":" + 'mypw')
},
crossDomain: true,
accepts: { json: "application/json" },
dataType: "json",
data: {
"query": "start n = node(*) return n",
"params": {}
},
success: function (data, textStatus, jqXHR) {
alert(textStatus);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
But I am getting this particular error:
XMLHttpRequest cannot load . No 'Access-Control-Allow-Origin' header
is present on the requested resource. Origin 'http://localhost:8383'
is therefore not allowed access. The response had HTTP status code
403.
Please help to solve this...
While setting up database server you have to whitelist the ip that may access it explicitly or add * so that all ip may access it.
By default Neo4j only accept request from localhost.
Do you have change param org.neo4j.server.webserver.address in neo4j-server.properties ?
Do you have access to the browser ?
Moreover, you don't use the good endpoint : change http://blackswantechnologiesosint.sb04.stations.graphenedb.com:24789/browser/ by http://blackswantechnologiesosint.sb04.stations.graphenedb.com:24789/db/data/transaction/commit`
See the documentation on this : http://neo4j.com/docs/stable/rest-api.html
Related
I am trying to implement a tampermonkey script that triggers an API call to a Jira instance to create a ticket with some information found in the page I am on (on a different domain).
Here's what I've tried:
async function createJiraTicket() {
let elements = await obtainThingsForCreatingJiraTicket();
let createJiraTicketUrl = `https://${jiraDomain}/rest/api/latest/issue`;
let requestDataForCreation =`
{
"fields": {
"project": { "key": "${elements.project}" },
"summary": "${elements.title}",
"description": "nothing",
"issuetype": {"name": "Issue" }
}
}`;
GM_xmlhttpRequest ( {
method: "POST",
url: `${http}://${createJiraTicketUrl}`,
user: 'user:pwd', // also tried user:'user', password:'pwd',
data: requestDataForCreation,
header: 'Accept: application/json',
dataType: 'json',
contentType: 'application/json',
onload: function (response) {
jiraTicketLog(`[Ajax] Response from Ajax call Received: `);
}
} );
However, when I run createJiraTicket(), I am getting the following error:
Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
at <anonymous>:1:7
I have established the correct #connect tags on the script, so I am pretty blind on where the problem may be...
Can someone help?
Thanks
So I came up with the answer to fix it, apparently it was a number of different details:
So,
Authorization had to be included onto the headers, coded on base64 and keyworded "Basic".
User-Agent needs to be overriden on headers, with any dummy string.
overrideMimeType needed to be set to json.
That all made the trick.
This was the working code.
let createJiraTicketUrl = `//${jiraDomain}/rest/api/latest/issue`;
let authentication = btoa('admin:foobar1');
GM.xmlHttpRequest({
method: "POST",
headers: {
'Accept': 'application/json',
"Content-Type": "application/json",
"Authorization": `Basic ${authentication}`,
"User-Agent": "lolol"
},
url: `${http}:${createJiraTicketUrl}`,
data: JSON.stringify(requestDataForCreation),
dataType: 'json',
contentType: 'application/json',
overrideMimeType: 'application/json',
onload: function (response) {
let url = `${http}://${jiraDomain}/browse/${JSON.parse(response.response).key}`;
log(`${JSON.parse(response.response).key} ticket created: ${url}`);
openJiraTicket(url);
}
I am working in rails application.I am using AJAX to send form data.Here problem is i couldn't send huge query string in while post data.Getting error Invalid request: HTTP element QUERY_STRING is longer than the (1024 * 10) allowed length.Is it possible to split the data based on length.If length exceeds maximum limits,it has to split the value and run one more time.How to implement this.Below the ajax call i am using.Parameter value is huge.
$.ajax({
url: "get_object",
type: 'POST',
dataType: "json",
data: {
parameter: parameter_name,
mac: macAdd,
protocol: protocol,
serialnumber: serialnumber,
oid: oid
},
success: function (result) {
console.log(result);
NProgress.done();
console.log("Call Success");
},
statusCode: {
404: function () {
console.log("Call failed");
}
}
});
})();
I am trying to post some data using Ajax, but it is not getting through when using content type of application/json (HTTP/1.1 406 Not Acceptable), however if I change the content type to 'application/x-www-form-urlencoded' then it does work.
Any ideas?
Ajax code extract:
$.ajax({
type: "POST",
data: {"hello":"test"},
url: "http://workingUrl/controller",
contentType : 'application/json',
cache: false,
dataType: "json",
.....
Web API 2:
public IHttpActionResult Post(testModel hello)
{
/// do something here
}
Model:
public class testModel
{
public string hello {get;set;}
public testModel()
{ }
}
Fiddler:
HTTP/1.1 406 Not Acceptable (In the IDE, I have a breakpoint in the Post method which is not hit).
I have tried adding a formatter to WebAPi.config, but no luck
config.Formatters.Add(new JsonMediaTypeFormatter());
Try with this JSON.stringify(TestData) as shown below -
var TestData = {
"hello": "test"
};
$.ajax({
type: "POST",
url: "/api/values",
data: JSON.stringify(TestData),
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: true,
success: function (data, status, jqXHR) {
console.log(data);
console.log(status);
console.log(jqXHR);
alert("success..." + data);
},
error: function (xhr) {
alert(xhr.responseText);
}
});
Output -
I've never specified contentType when I've done this and it's always works. However, if it works when you use 'application/x-www-form-urlencoded' then what's the problem?
I do see a couple thing off in your ajax. I would do this
$.ajax({
type: "POST",
data: {hello:"test"},
url: "http://workingUrl/controller/Post",
cache: false)}
For data, maybe quotes around the variable name will work but I've never had them there.
Next, the url in the ajax call doesn't have the name of your controller action. That needs to be in there.
I have the following method in my Web API controller
[HttpGet]
[ActionName("GetByModule")]
public Object Get([FromUri]int id)
{
//var dblayer = new Db(WebConfigurationManager.ConnectionStrings["ConnectionString"]);
var annDb = new ContactsDB(WebConfigurationManager.ConnectionStrings["ConnectionString"]);
return annDb.GetContacts(id).Tables[0];
}
Here i the Jquery code which i am using to call the method
$.ajax({
type: "GET",
contentType: "application/json",
url: link,
data: null,
dataType: "json",
success: function (data) {
alert(data.d);
},
error: function (jqXHR, textStatus, err) {
alert("Error");
}
});
The URL which is getting called is
http://localhost:56834/api/Contacts/GetByModule?id=9
But i keep getting HTTP 405 Method Not Allowed on calling it from Jquery.
Any idea what i may be doing wrong.
Thanks in Advance
Can you make sure you are making a "GET" request? (maybe from Fiddler or browser's debug mode). I say this because you seem to setting the "contentType" property in your jquery, which ideally should not be present as you should not be sending body in a "GET" request. Could you share your full raw request(may be from Fiddler)?
I have the following jQuery ajax request in a .js file:
$.ajax({
type: "GET",
url: "Download.aspx/ZipCheck",
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
The request fails and an alert pops up that says "200 OK". However, if I change the ajax request type to "POST" then it works and I have an alert that pops up with the expected data being returned from Download.aspx/ZipCheck.
Why does the GET fail, and why does the POST succeed? My understanding must be flawed about the difference between the two, because I thought that a GET request still would return something from the server.
WebMethods are by default restricted to POST, you need to explicitly enable the GET request, for example using UseHttpGet on the ScriptAttribute, like this:
[WebMethod, ScriptMethod(UseHttpGet=true)]
public thing ZipCheck() {
//return object
}