Ajax delete method giving error - Fuseki server - ajax

I am having trouble with update and delete through ajax. I am getting an error in SPARQL Query but the query should be fine. Here is my code:
function deletePerson(per){
myQuery= ["DELETE{",
"<"+per+"> ?p ?o.",
"?s1 ?p1 <"+per+">.",
"}WHERE{",
"<"+per+"> ?p ?o.",
"OPTIONAL{",
"?s1 ?p1 <"+per+">.}}"].join(" ");
window.alert(myQuery);
$.ajax({
dataType: 'text',
type: 'POST',
url: "http://localhost:3030/Test/update",
data: {'query': myQuery, 'update': 'delete', '_method': 'delete'},
success: function(data) {
window.alert('Deleted');
},
error: myError
});
console.log('After .ajax');
}
The error I am getting is Sparql Error 400: Encountered "EOF" at line 1, column 6.?Was expecting:? "{" ...?

Related

Parser Error: unexpected character at line 3 column 1 of the JSON data

I have a project and I host it into my local server.
path:C:\inetpub\wwwroot
and my project worked as expected, but when I create a directory inside C:\inetpub\wwwroot like
C:\inetpub\wwwroot\Link1 ajax post method shows me-
SyntaxError: JSON.parse: unexpected character at line 3 column 1 of the JSON data
Am I missing something???
any kind of help would be appreciated.
code in js file:
var besiscid = $("#basictypeids").data("kendoDropDownList").value();
var list = {
BASICTYPEID: besiscid
};
$.ajax({
url: "/Invoice/_GetInvoiceNumber",
data: JSON.stringify(list),
type: "POST",
contentType: "application/json;charset=utf-8",
dataType: 'json',
success: function (objDAL) {
alert(objDAL.DINVOICENO);
},
error: function (jqXHR, textStatus, error) {
alert(jqXHR);
alert(textStatus);
alert(error);
}
});

Ajax fetching data.But also showing error with datatype Json.But working with datatype html

I am trying to fetch the data from php file by passing dynamic query string on ajax URL section.But while I changing datatype html to json. It is popping up error
jQuery(".nks_cc_trigger_element").click(function(){
var str = jQuery(this).attr("data-product_id");
jQuery.ajax({
url: "/ajax_product.php?q="+parseInt(str),
type: 'POST',
dataType: 'json',
success: function(result){
jQuery("#nks-content-1 > div").html(result);
console.log(result);
},
error: function(jqXHR,error, errorThrown) {
if(jqXHR.status&&jqXHR.status==400){
alert(jqXHR.responseText);
}else{
alert("Something went wrong");
alert(jqXHR.responseText);
}
}
}).done(function() {
});
>>PHP CODE
echo json_encode($data) ;
Use the data key/attribute and use the POST method, but don't pass the queries through the URL.
$(".nks_cc_trigger_element").click(function(){
var str = $(this).attr("data-product_id");
$.ajax({
url: "ajax_product.php",
type: 'POST',
dataType: 'json',
data: //json data,
success: function(result){
//success code
},
error: function(jqXHR, error, errorThrown) {
//error code
}
});
});

Ajax POST request to ODATA service throws Invalid HTTP status code 501

I have the following code which I wish to use for inserting a record into an entity of an ODATA service.
The post request throws a XMLHttpRequest cannot load Invalid HTTP status code 501.
Apparently GET request works fine. Can anyone suggest a way to find out the problem ? Does my WCF Service has a problem ?
var data = { application_id: 777 , user_id: 'test' };
var data = JSON.stringify(data);
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
datatype: 'json',
url: oDataURL + 'application_admins',
data: data,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
account = data.d;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});

get data from geonames using json

Im using this:
$.ajax({
url: 'http://api.geonames.org/searchJSON?username=presis',
dataType: "jsonp",
data: {
name: city,
countryName: country,
maxRows: 1
},
jsonp: "jsonp",
success: function(data) {
$.map(data.geonames, function(item) {
return {
value: item,
};
});
}
});
I just can't get it to work. What could the problem be?
In my chrome console i get "Uncaught SyntaxError: Unexpected token :" in the searchJSON object.

AJAX put request failing?

Doing an ajax get request works as expected using the following code:
$.ajax({
type: "GET",
contentType: "application/json",
url: "http://someSeceretUrl/test/document,
dataType: "jsonp",
success: function(msg) {
console.log(msg);
},
error: function(a,b,c) {
console.log(a);
console.log(b);
console.log(c);
}
});
But a PUT ajax call using the following code:
$.ajax({
type: "PUT",
contentType: "application/json",
url: "http://someObscureURL/test/mrmer1",
dataType: "jsonp",
data: {"name":"mike"},
success: function(msg) {
console.log(msg);
},
error: function(a,b,c) {
console.log("XMLHttpRequest: " + a);
console.log("textStatus: " + b);
console.log("errorThrown: " + c);
}
});
results in the following console output:
XMLHttpRequest: [object XMLHttpRequest]
textStatus: null
errorThrown: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "http://static.kobj.net/kobj-static-20100219162227.js Line: 371"]
I am thinking that something is blocking the PUT request, but I don't know.
What am I doing wrong?
Thanks!
I suppose you are hitting cross domain restrictions. I wouldn't be surprised if http://username:password#somehost is considered as cross domain.
When I've done PUT requests in the past, I've found that not passing the contentLength header results in an exception being thrown, just a thought

Resources