1

I want to save on a .ttl file a type 'person' resource from a javascript function:

this is my sparql query:

@app.route('/registraAnnotatore/<author>+<mail>', methods=['POST'])
    def registraAnnotatore(author,mail):
    sparql = SPARQLWrapper("http://localhost:3030/data/update")
    mailto = "<mailto:"+mail+">"
    sparql.setQuery("""
        PREFIX  aop: <http://vitali.web.cs.unibo.it/AnnOtaria/person/>
        PREFIX  foaf: <http://xmlns.com/foaf/0.1/>
        PREFIX  schema: <http://schema.org/>

    INSERT DATA
    { """+mailto+""" a foaf:Person;
      foaf:name """+author+""";
      schema:email """+mail+""".
    }

     """)
    sparql.setReturnFormat(JSON)
    results = sparql.query().convert()
    results = results['results']['bindings']
    results = json.dumps(results)

    return results 

and this is my javascript function with the ajax call:

 function salvaRemoto(){

    $.ajax({
     method: 'GET',
     url: '/verificaAnnotatore/'+fullname+'+'+email,
     success: function(d) {
     d = JSON.parse(d);
     alert(d.length);
     if(d.length>0){
         }else{
     //registrazione nuovo utente
     $.ajax({
        method: 'POST',
        url: '/registraAnnotatore/'+fullname+'+'+email,
        success: function() {   
        alert("Utente registrato !!!");

        },
        error: function(a,b,c) {

        alert(a + ' ' + b + ' ' + c);
       }
      });
     } 

    },
    error: function(a,b,c) {
    alert(a + ' ' + b + ' ' + c);
    }
   }); 
  }

I don't know why it doesnt' work, any ideas?

nickmeck
  • 17
  • 4
  • I don't expect that you end up with the query that you want. Try printing out the query and checking it with sparql.org's query validator. – Joshua Taylor Oct 07 '14 at 15:22
  • And "it doesn't work" isn't enough information. Where are you trying to run this? What error message do you get? Do you get any backtrace? – Joshua Taylor Oct 07 '14 at 15:22

1 Answers1

1

Your endpoint only accepts POST request: @app.route('/registraAnnotatore/<author>+<mail>', methods=['POST']) and in your client you are doing a GET request method: 'GET',

That's why you're getting 405 METHOD NOT ALLOWED for this endpoint ( /registraAnnotatore/<author>+<mail>).

aabilio
  • 1,697
  • 12
  • 19