如何从jquery / ajax向php发送编码查询(或字符串)?

时间:2015-10-01 13:20:09

标签: php jquery ajax sparql

我有一个字符串,表示要发送到php服务器的sparql查询。在该查询中,我有一个部分,它由jquery方法encodedURIComponent编码。

问题是,如果我从php端打印字符串,我看到字符串的编码部分已到达解码,这就是为什么我得到由以下错误引起的500内部服务器错误,结果是拒绝发送查询。

这是错误:

Fatal error: Uncaught exception 'EasyRdf_Exception' with message 'HTTP request for SPARQL query failed: Error 400: Encountered " "<" "< "" at line 2, column 948. Was expecting one of: <IRIref> ... <PNAME_NS> ... <PNAME_LN> ... <BLANK_NODE_LABEL> ... <VAR1> ... <VAR2> ... "true" ... "false" ... <INTEGER> ... <DECIMAL> ... <DOUBLE> ... <INTEGER_POSITIVE> ... <DECIMAL_POSITIVE> ... <DOUBLE_POSITIVE> ... <INTEGER_NEGATIVE> ... <DECIMAL_NEGATIVE> ... <DOUBLE_NEGATIVE> ... <STRING_LITERAL1> ... <STRING_LITERAL2> ... <STRING_LITERAL_LONG1> ... <STRING_LITERAL_LONG2> ... "(" ... <NIL> ... "}" ... "[" ... <ANON> ... Fuseki - version 2.0.0 (Build date: 2015-03-08T09:49:20+0000) ' in C:\xamp_workbench\xampp\htdocs\heisenberg\easyrdflib\EasyRdf\Sparql\Client.php:284 Stack trace: #0 C:\xamp_workbench\xampp\htdocs\heisenberg\easyrdflib\EasyRdf\Sparql\Client.php(174): EasyRdf_Sparql_Client->request('update', 'PREFIX oa: <htt... in C:\xamp_workbench\xampp\htdocs\heisenberg\easyrdflib\EasyRdf\Sparql\Client.php on line 284

这是将查询发送到php

的方法
function sendQuery(jsonDaInviare) {
console.log(jsonDaInviare);

 $.ajax({
   //headers: {'Content-Type': 'contentType: "application/x-www-form-urlencoded;charset=UTF-8",'},
    url: 'php/AutomaticScrape.php',
    data: "annotazioniDoc="+jsonDaInviare,
    type: 'POST',
    success: function (result) {
        arrayAnnotazioni = [];
        json = "";
    },
    error: function (jqXHR, textStatus, errorThrown) {
        alert("Errore nel mandare il json al server");
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
    }
});

}

这是从jquery

重新获取查询的php方法
if(isset($_POST['annotazioniDoc'])){
// here I find that the encoded part of the string arrives decoded
echo $_POST['annotazioniDoc'];
// this is commented because the query returns me that error
// $jsonDaMandare = $GLOBALS['sparql']->update($json);

}

更准确地说,这是编码字符串的一部分:

<http://rivista-statistica.unibo.it/article/view/4601_cited_A.M.%20MATHAI%20…Linear%20Algebra%20and%20its%20Applications%20396%2C%20pp.%20317-328._ver1>

因此这是从php返回的方式:

<http://rivista-statistica.unibo.it/article/view/4601_cited_A.M. MATHAI (2005), A pathway to matrix - variate gamma and normal densities, Linear Algebra and its Applications 396, pp. 317-328._ver1>de here

修改

我已经解决了这个问题:

$.post( "php/AutomaticScrape.php", { annotazioniDoc: jsonDaInviare }, function() { 
        // do stuff 

})

0 个答案:

没有答案