Quantcast

how to post an xml string to the server using ajax

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to post an xml string to the server using ajax

dolot
I have a situation where I have a dojo dialog box and the user will enter xml into a textarea element.  I then want to upload that data asynchronously to the server.  I would like to simply take the xml string just like it is and send it to the server and parse it there rather than parsing it client side.  I've tried several different things but so far am not having any success.  I'm not sure if the problem is client side or server side (asp.net mvc v.4 is the server side).

Here's the basic client side code I've been working with:

        var target = "/Api/" + controllerName + "/updateFeatureCoords?MapFeatureId=" + featureId + "&MapLayerId=" + layerId;
        var postData = dojo.query(".featureCoordsUploadTextArea", domRoot)[0].innerHTML;

        require(["dojo/request/xhr"], dojo.hitch(this, function (xhr) {
            xhr(target, {
                method: "POST",
                data: postData,
                handleAs: "json",
                preventCache: false
            }).then(
                this.doCoordImportSuccess
            , function (err) {
                // Handle the error condition
                this.evalBadResult
            });

        }));

Anybody have an ideas what may be wrong?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to post an xml string to the server using ajax

Ken Benjamin
A couple of potential problem areas:

handleAs: 'json' should be handleAs: 'text' (the default).

You may need to set a Content-Type header for your .NET controller to parse it properly. By default, it is set to: { 'Content-Type': 'application/x-www-form-urlencoded' } but you probably want { 'Content-Type': 'text/xml' }. Try it this way:

dolot wrote
        var target = "/Api/" + controllerName + "/updateFeatureCoords?MapFeatureId=" + featureId + "&MapLayerId=" + layerId;
        var postData = dojo.query(".featureCoordsUploadTextArea", domRoot)[0].innerHTML;

        require(["dojo/request/xhr"], dojo.hitch(this, function (xhr) {
            xhr(target, {
                method: "POST",
                data: postData,
                handleAs: "text",
                preventCache: false,
                headers: { 'Content-Type': 'text/xml' }
            }).then(
                this.doCoordImportSuccess
            , function (err) {
                // Handle the error condition
                this.evalBadResult
            });

        }));

Kenneth Benjamin

Web Application Architect for Hire

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: how to post an xml string to the server using ajax

dolot

Thanks so much for your response, Ken.  Unfortunately, this still hasn’t solved the issue.  I’m not sure really where the problem resides – is it something on the client side or something about how I have things setup in the MVC controller on the server. 

 

I’ll keep investigating.

 

Have a great day!

Dave Southern

 

From: Ken Benjamin [via Dojo Toolkit] [mailto:[hidden email]]
Sent: Tuesday, April 05, 2016 11:24 AM
To: dolot
Subject: Re: how to post an xml string to the server using ajax

 

A couple of potential problem areas:

handleAs: 'json' should be handleAs: 'text' (the default).

You may need to set a Content-Type header for your .NET controller to parse it properly. By default, it is set to: { 'Content-Type': 'application/x-www-form-urlencoded' } but you probably want { 'Content-Type': 'text/xml' }. Try it this way:

dolot wrote

        var target = "/Api/" + controllerName + "/updateFeatureCoords?MapFeatureId=" + featureId + "&MapLayerId=" + layerId;
        var postData = dojo.query(".featureCoordsUploadTextArea", domRoot)[0].innerHTML;

        require(["dojo/request/xhr"], dojo.hitch(this, function (xhr) {
            xhr(target, {
                method: "POST",
                data: postData,
                handleAs: "text",
                preventCache: false,
                headers: { 'Content-Type': 'text/xml' }
            }).then(
                this.doCoordImportSuccess
            , function (err) {
                // Handle the error condition
                this.evalBadResult
            });

        }));

Kenneth Benjamin

Web Application Architect for Hire

 


If you reply to this email, your message will be added to the discussion below:

http://dojo-toolkit.33424.n3.nabble.com/how-to-post-an-xml-string-to-the-server-using-ajax-tp4006826p4006827.html

To unsubscribe from how to post an xml string to the server using ajax, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to post an xml string to the server using ajax

Peter_dojo
Dear Dave,

in your webbrowser (chrome or firefox), before you submit the data, press F12 to open the debugger.

There is tab for the Network traffic

You should be able to inspect the data request that is sent - and so check if the client sends the data correctly.

Peter
On 05/04/16 19:34, dolot wrote:

Thanks so much for your response, Ken.  Unfortunately, this still hasn’t solved the issue.  I’m not sure really where the problem resides – is it something on the client side or something about how I have things setup in the MVC controller on the server. 

 

I’ll keep investigating.

 

Have a great day!

Dave Southern

 

From: Ken Benjamin [via Dojo Toolkit] [mailto:[hidden email]]
Sent: Tuesday, April 05, 2016 11:24 AM
To: dolot
Subject: Re: how to post an xml string to the server using ajax

 

A couple of potential problem areas:

handleAs: 'json' should be handleAs: 'text' (the default).

You may need to set a Content-Type header for your .NET controller to parse it properly. By default, it is set to: { 'Content-Type': 'application/x-www-form-urlencoded' } but you probably want { 'Content-Type': 'text/xml' }. Try it this way:

dolot wrote

        var target = "/Api/" + controllerName + "/updateFeatureCoords?MapFeatureId=" + featureId + "&MapLayerId=" + layerId;
        var postData = dojo.query(".featureCoordsUploadTextArea", domRoot)[0].innerHTML;

        require(["dojo/request/xhr"], dojo.hitch(this, function (xhr) {
            xhr(target, {
                method: "POST",
                data: postData,
                handleAs: "text",
                preventCache: false,
                headers: { 'Content-Type': 'text/xml' }
            }).then(
                this.doCoordImportSuccess
            , function (err) {
                // Handle the error condition
                this.evalBadResult
            });

        }));

Kenneth Benjamin

Web Application Architect for Hire

 


If you reply to this email, your message will be added to the discussion below:

http://dojo-toolkit.33424.n3.nabble.com/how-to-post-an-xml-string-to-the-server-using-ajax-tp4006826p4006827.html

To unsubscribe from how to post an xml string to the server using ajax, click here.
NAML



View this message in context: RE: how to post an xml string to the server using ajax
Sent from the Dojo Toolkit mailing list archive at Nabble.com.




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: how to post an xml string to the server using ajax

dolot

How can you tell I’m a noob?  ;)

 

It turns out that the data is getting there, I just didn’t know how to view it on the server.  Finally figured out how to access it through Request.Content.ReadAsStringAsync().Result

 

But thanks for the reminder.  I always forget about the f12 tools (we’re in IE, btw)

 

Have a great day!

Dave Southern

 

From: Peter_dojo [via Dojo Toolkit] [mailto:[hidden email]]
Sent: Tuesday, April 05, 2016 1:06 PM
To: dolot
Subject: Re: how to post an xml string to the server using ajax

 

Dear Dave,

in your webbrowser (chrome or firefox), before you submit the data, press F12 to open the debugger.

There is tab for the Network traffic

You should be able to inspect the data request that is sent - and so check if the client sends the data correctly.

Peter
On 05/04/16 19:34, dolot wrote:

Thanks so much for your response, Ken.  Unfortunately, this still hasn’t solved the issue.  I’m not sure really where the problem resides – is it something on the client side or something about how I have things setup in the MVC controller on the server. 

 

I’ll keep investigating.

 

Have a great day!

Dave Southern

 

From: Ken Benjamin [via Dojo Toolkit] [mailto:[hidden email]]
Sent: Tuesday, April 05, 2016 11:24 AM
To: dolot
Subject: Re: how to post an xml string to the server using ajax

 

A couple of potential problem areas:

handleAs: 'json' should be handleAs: 'text' (the default).

You may need to set a Content-Type header for your .NET controller to parse it properly. By default, it is set to: { 'Content-Type': 'application/x-www-form-urlencoded' } but you probably want { 'Content-Type': 'text/xml' }. Try it this way:

dolot wrote

        var target = "/Api/" + controllerName + "/updateFeatureCoords?MapFeatureId=" + featureId + "&MapLayerId=" + layerId;
        var postData = dojo.query(".featureCoordsUploadTextArea", domRoot)[0].innerHTML;

        require(["dojo/request/xhr"], dojo.hitch(this, function (xhr) {
            xhr(target, {
                method: "POST",
                data: postData,
                handleAs: "text",
                preventCache: false,
                headers: { 'Content-Type': 'text/xml' }
            }).then(
                this.doCoordImportSuccess
            , function (err) {
                // Handle the error condition
                this.evalBadResult
            });

        }));

Kenneth Benjamin

Web Application Architect for Hire

 


If you reply to this email, your message will be added to the discussion below:

http://dojo-toolkit.33424.n3.nabble.com/how-to-post-an-xml-string-to-the-server-using-ajax-tp4006826p4006827.html

To unsubscribe from how to post an xml string to the server using ajax, click here.
NAML

 


View this message in context: RE: how to post an xml string to the server using ajax
Sent from the Dojo Toolkit mailing list archive at Nabble.com.



--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


If you reply to this email, your message will be added to the discussion below:

http://dojo-toolkit.33424.n3.nabble.com/how-to-post-an-xml-string-to-the-server-using-ajax-tp4006826p4006829.html

To unsubscribe from how to post an xml string to the server using ajax, click here.
NAML

Loading...