Using JavaScript to search the Sesame triplestore

My current challenge involves retrieving data from a Sesame Triplestore using ajax. It seems like I might be dealing with a CORS issue, and to address this, I am considering utilizing the CORS Filter. Is my assumption on point, or is there something specific in the code that needs altering?

$(document).ready(function() {
      $.ajax({
                url: 'http://localhost:8080/openrdf-sesame/repositories/Test12',
                dataType: 'jsonp', 
                data: { 
                    queryLn: 'SPARQL',
                    query: "SELECT * WHERE { ?s ?p ?o }", 
                    limit: 100,
                    infer: 'true',
                    Accept: 'application/sparql-results+json'
                },
                success: displayData, 
                error: displayError
        });
    });

    function displayError(xhr, textStatus, errorThrown) {
        alert(textStatus);
        alert(errorThrown);
    }

    function displayData(data) {
        var header = $('#result thead').append('<tr/>');
        $.each(data.head.vars, function(key,value) {
            header.append("<th>" + value + "</th>");
        });


        $.each(data.results.bindings, function(index, bs) {
        var row = $('<tr/>');
        $.each(data.head.vars, function(key, varname) {
            row.append("<td>" + bs[varname].value + "</td>"); 
            });
        $("#result tbody").after(row);
        });
    }

The browser console displays the following error:

Resource interpreted as Script but transferred with MIME type application/sparql-results+json: "http://localhost:8080/openrdf-sesame/repositories/Test12?callback=jQuery213…=100&infer=true&Accept=application%2Fsparql-results%2Bjson&_=1429660808937". jquery-2.1.3.min.js:4
send jquery-2.1.3.min.js:4
n.extend.ajax jquery-2.1.3.min.js:4
(anonymous function) index_wip3.html:10
j jquery-2.1.3.min.js:2
k.fireWith jquery-2.1.3.min.js:2
n.extend.ready jquery-2.1.3.min.js:2
I jquery-2.1.3.min.js:2
Uncaught SyntaxError: Unexpected token : Test12:2

When attempting to replace application/sparql-results+json with application/json, the error remains unchanged.

Switching the dataType to "json" instead of "jsonp" results in a different error message:

XMLHttpRequest cannot load http://localhost:8080/openrdf-sesame/repositories/Test12?queryLn=SPARQL&que…HERE+%7B+%3Fs+%3Fp+%3Fo+%7D&limit=100&infer=true&Accept=application%2Fjson. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 

Answer №1

One specific error that is Chrome-specific is related to the media type application/sparql-results+json. Chrome does not recognize this as a scripting-compatible media type. To resolve this issue, you can simply replace it with application/json in the Accept parameter of your request.

It's important to note that the issue mentioned above is not CORS-related. Cross-Origin Resource Sharing (CORS) involves adding HTTP headers to allow cross-domain scripting calls from browsers. In this case, JSONP callbacks are being used, which is an older and slightly less secure method compared to CORS.

As for Sesame Server, it currently does not support CORS headers. However, there are plans to add this feature in the future: .

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Could you confirm if this is a TypeScript function?

Recently, while delving into the vue-next source code, I stumbled upon a particular line that left me puzzled. Due to my limited experience with TypeScript, I found myself struggling to grasp its purpose. Could someone clarify if this snippet constitutes ...

Top method for handling multiple conditions - JavaScript

I created a customized function to create a responsive carousel with multiple images per slide. (Unfortunately, I couldn't get Owl Carousel to work on my Angular project, but that's not the focus here). The number of images displayed per slide i ...

Can you provide guidance on implementing StyledComponents within the app folder of Next.js version 13?

Quoting information from the Next.js documentation: Attention: CSS-in-JS libraries that rely on runtime JavaScript are currently not compatible with Server Components. The following libraries are supported in Client Components within the app directory: s ...

Encountering a registration error persistently: [TypeError: Network request failed]

Currently, I am in the process of developing an application using React for the frontend and node.js for the backend. However, I have encountered a persistent network error whenever I try to sign up or log in. What puzzles me is that when I test the API en ...

Guide to Increasing Table Index within Nested Loop in Vue.js 3

How can I increment table indices within a nested loop in Vue.js 3? I am currently working with two-level deep arrays using Vue.js, and I need an index that starts at 1 and increases for each item in the top-level array. The desired output is as follows: ...

Forwarding information and transferring data from a Node server to ReactUIApplicationDelegate

I am currently working on a NodeJS server using Express and React on the front-end. I am trying to figure out how to send data from the server to the front-end without initiating a call directly from the front-end. The usual solutions involve a request fro ...

Tips on navigating to a URL with a component in React without losing the passed props

When the onClick event is triggered, I aim to redirect to a new component with props passed to it along with a new URL. My App.js import React from "react"; import Main from "./Components/Main/Main"; import "bootstrap/dist/css/boo ...

Fluidly adjust text field and label fields in forms

I came across a code snippet that allows for dynamically adding form text fields. However, I needed to ensure that each text field has a corresponding label which increments by one every time a new field is added. While I have successfully added the labels ...

Are HTTP GET requests and AJAX calls interchangeable?

I've been curious about this and haven't found a clear answer anywhere else. Is an HTTP GET request asynchronous? If so, what are the main distinctions? I'm not interested in opinions, just concrete answers. My searches have only resulted ...

Tips for utilizing an event listener for a submission button

I am encountering a problem with this event listener. I attempted to add an event listener to the submit button, but it seems to be inactive. I can't figure out what mistake I have made! Here is my code: const form = document.getElementById("form") ...

show information through ajax when utilizing $_GET

Is there a way to update data without refreshing the page by utilizing '$_GET' in PHP? Currently, I have a setup that increments correctly when I click on add, but it always triggers a page refresh. How can this be achieved using Ajax to achiev ...

Tips for ensuring the safety of your AJAX requests when using PHP and jQuery

Identifying the Challenge Lately, I have been exploring various AJAX methods to send data to a server for processing and storage in a MySQL database. The backend script that handles the AJAX request, api.php, is equipped with PHP's PDO prepared state ...

Using the Upload feature in ReactJS

I have been searching high and low for assistance in creating a component within React that can handle file uploads to a specific endpoint I have established. I have experimented with various options, including trying to integrate filedropjs. However, I u ...

What is the process for obscuring items using the depth buffer in three.js?

In my current project using three.js, I am working on a 2D game where I need to render background scenery followed by a transparent quad that still writes values to the depth buffer even though it has an opacity of zero. The challenge arises when trying to ...

Various web browsers are displaying distinct jQuery errors when executing the code

I'm currently working on validating and uploading images using multiple accept inputs with the help of jQuery, AJAX, and PHP. I have successfully added a validation function that is working correctly, but the form is not submitting. Additionally, Chro ...

What is the best way to incorporate parallax scrolling in the center of a webpage?

I am trying to implement a parallax scrolling effect in the middle of my page, but it seems to be causing issues once I reach that section while scrolling. I attempted to use intersection observer, but unfortunately, it did not resolve the problem. const ...

Utilizing d3 for Nested jQuery Accordions

I'm facing a challenging issue trying to nest jQuery accordions using d3. The difficulty arises from the complexity of creating HTML structures like the one below with nested accordions, and utilizing d3's nest and data binding functionalities: ...

Celery update_state() function malfunctioning

I'm experiencing an issue with the "current_task.update_state()" function not working while creating a progress bar. Below is a simple example from my "task.py" definition. from celery import shared_task, current_task @shared_task def mytask(a): ...

Utilize jQuery to extract data from a Steam page in JSON format

Although I have researched extensively on this topic, it is still not functioning as desired. I came across this Steam page in JSON format. My aim is to extract the lowest_price variable without using PHP as I am incorporating it into my Chrome extension. ...

Looking to add a close button to the iFrame, but having trouble getting it to function when clicked

In my project built with Meteor, I have integrated an iframe to display specific content to the user. The iframe is functioning as expected, but I am looking to add a close button that will effectively unload the iframe when clicked. I attempted to imple ...