POST request to UPDATE rows

后端 未结 4 1371
死守一世寂寞
死守一世寂寞 2021-01-29 00:13

I\'m kind of newbie in javascript so I\'m looking for some help to create a way to drag and drop geocoding markers, to allow interactive changing addresses. I believe this is po

4条回答
  •  不思量自难忘°
    2021-01-29 00:53

    You must POST to the Fusion Tables API to update a column, but currently you can't do this directly from JavaScript as Google does not set the CORS headers to allow cross-domain posting to their API.

    So if you want to do this, you have to "relay" your request through your webserver or something similar. I do it with the following PHP script, then I post the request via JavaScript to my PHP script. And finally, you have to authenticate yourself using OAuth.

    $url = "http://www.google.com/fusiontables/api/query";
    $relay = new PostRelay($url,$_POST);
    echo $relay->relay();
    

    And in class PostRelay the method relay() is defined, the $_POST holds all posted data (represented by $this->data in my class):

    public function relay()
    {
        $url = $this->getUrl();
        $this->curlHandler = curl_init($url);
        curl_setopt($this->curlHandler, CURLOPT_POST, true);
        curl_setopt($this->curlHandler, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->curlHandler, CURLOPT_TIMEOUT, 30);
        curl_setopt($this->curlHandler, CURLOPT_FOLLOWLOCATION, 1);
    
        if($this->data != null) {
            curl_setopt($this->curlHandler, CURLOPT_POSTFIELDS, $this->getData());
        }
    
        $remote_answer = curl_exec($this->curlHandler);
    
        if(curl_errno($this->curlHandler) != 0) {
            $msgErrorNo = "cURL Errornumber: ".curl_errno($this->curlHandler);
            $msgError = "cURL Error: ".curl_error($this->curlHandler);
            throw new RemoteException($url,$msgErrorNo." ".$msgError);
        }
        return $remote_answer;
    }
    

提交回复
热议问题