Venkatesan GB
Venkatesan GB

Reputation: 103

How to make HTTP POST request call from Dojo version 1.7 or below?

I am new to dojo and using version 1.7.Making service call from dojo now i need to change the request method from GET to POST. For GET request currently i am using dojo/io/script, for POST should use dojo/request/script suggested by https://dojotoolkit.org/reference-guide/1.10/dojo/io/script.html . But dojo/request/script introtuced in dojo 1.8. Is there any other method to call POST types or need to go with dojo 1.8? Help me to resolve this ,thanks in advance.

Upvotes: 0

Views: 1006

Answers (1)

Bourbia Brahim
Bourbia Brahim

Reputation: 14712

It's preferable not to use dojo/io/script , and this last is deprecated in 1.8 version as per as listed in documentation .

If You want to call a specific script file in order to embed it into a page or an app , use dojo/request/script ,

So it's better to migrate to 1.8

Otherwise if you want to call an endpoint that return data , html , or some results , just use only the dojo/request

require(["dojo/request"], function(request){
    request.post(url, {data:data, method: 'POST', handleAs: 'json'}).then(
        function(response){
            //success
        },
        function(error){
            //error
        }
    );
});

Upvotes: 0

Related Questions