# Javascript with ElasticSearch - trying to make POST wortk

**URL:** <https://discuss.elastic.co/t/javascript-with-elasticsearch-trying-to-make-post-wortk/7651>\
**Category:** Elasticsearch\
**Created:** [May 11, 2012, 5:00am UTC](https://discuss.elastic.co/t/javascript-with-elasticsearch-trying-to-make-post-wortk/7651 "2012-05-11T05:00:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duke\_Dougal](https://avatars.discourse-cdn.com/v4/letter/d/f0a364/32.png) [@Duke\_Dougal](https://discuss.elastic.co/u/Duke_Dougal)\
**Post date:** [May 11, 2012, 5:00am UTC](https://discuss.elastic.co/t/javascript-with-elasticsearch-trying-to-make-post-wortk/7651/1 "2012-05-11T05:00:56Z")

</div>

For the code below, if the type is set to POST in the code then the  
ElasticSearch server returns an error 500. If type is set to GET,  
then the query works. Any idea why?

The URL in the code is not publicly accessible and is behind a  
firewall.

 var myURL = 'http://ec2-54-248-13-166.ap- northeast-1.compute.amazonaws.com:9200/people/person/\_search';

```
        var query = {
            q: 'fullname:smith',
            pretty:'true',
            size:100
        };

        $.ajax({
                url: myURL,
                type: "Post",
                dataType: 'json',
                data: query,
                success: function( data ) { alert(data);}
              });
    </script>
</body>

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 11, 2012, 5:36am UTC](https://discuss.elastic.co/t/javascript-with-elasticsearch-trying-to-make-post-wortk/7651/2 "2012-05-11T05:36:25Z")

</div>

Just wondering if you should not write POST instead of Post ?

Envoyé de mon iPad

Le 11 mai 2012 à 07:00, Duke Dougal [dukedougal@gmail.com](mailto:dukedougal@gmail.com) a écrit :

> For the code below, if the type is set to POST in the code then the  
> Elasticsearch server returns an error 500. If type is set to GET,  
> then the query works. Any idea why?
> 
> The URL in the code is not publicly accessible and is behind a  
> firewall.
> 
> var myURL = 'http://ec2-54-248-13-166.ap- northeast-1.compute.amazonaws.com:9200/people/person/\_search';
> 
> ```
> var query = {
> q: 'fullname:smith',
> pretty:'true',
> size:100
> };
> 
> $.ajax({
> url: myURL,
> type: "Post",
> dataType: 'json',
> data: query,
> success: function( data ) { alert(data);}
> });
> </script>
> 
> ```

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [May 11, 2012, 7:29am UTC](https://discuss.elastic.co/t/javascript-with-elasticsearch-trying-to-make-post-wortk/7651/3 "2012-05-11T07:29:13Z")

</div>

Make sure you are not running into XSS (  
[Cross-site scripting - Wikipedia](http://en.wikipedia.org/wiki/Cross-site_scripting)).

On Fri, May 11, 2012 at 7:36 AM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Just wondering if you should not write POST instead of Post ?
> 
> Envoyé de mon iPad
> 
> Le 11 mai 2012 à 07:00, Duke Dougal [dukedougal@gmail.com](mailto:dukedougal@gmail.com) a écrit :
> 
> > For the code below, if the type is set to POST in the code then the  
> > Elasticsearch server returns an error 500. If type is set to GET,  
> > then the query works. Any idea why?
> > 
> > The URL in the code is not publicly accessible and is behind a  
> > firewall.
> > 
> > var myURL = 'http://ec2-54-248-13-166.ap- northeast-1.compute.amazonaws.com:9200/people/person/\_search';
> > 
> > ```
> > var query = {
> > q: 'fullname:smith',
> > pretty:'true',
> > size:100
> > };
> > 
> > $.ajax({
> > url: myURL,
> > type: "Post",
> > dataType: 'json',
> > data: query,
> > success: function( data ) { alert(data);}
> > });
> > </script>
> > 
> > ```

---

<div class="post-metadata">

**Author:** ![VishwanathShankar](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@VishwanathShankar](https://discuss.elastic.co/u/VishwanathShankar)\
**Post date:** [December 1, 2014, 3:12pm UTC](https://discuss.elastic.co/t/javascript-with-elasticsearch-trying-to-make-post-wortk/7651/4 "2014-12-01T15:12:31Z")

</div>

Can you try this:

var query = {  
q: 'fullname:smith',  
pretty:'true',  
size:100  
};

```
        $.ajax({ 
                url: myURL, 
                type: "Post", 
               <b> crossDomain: true,
	    dataType: 'json',
	    data: JSON.stringify(query),</b>
                success: function( data ) { alert(data);} 
              });
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:46am UTC](https://discuss.elastic.co/t/javascript-with-elasticsearch-trying-to-make-post-wortk/7651/5 "2017-07-06T00:46:48Z")

</div>


