1

My data is an xml element & I want send PUT request with JavaScript. How do I do this ?

For reference : Update Cell

EDIT : As per fredrik suggested, I did this :

<form id="submitForm" method="PUT" enctype="application/atom+xml" action="https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1">
            <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
                <id>https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1</id>
                <link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1'/>
                <gs:cell row='2' col='1' inputValue='300'/>
            </entry>
            <input type="submit" value="submit"/>
        </form>

However, it doesn't write back but positively it returns xml file like :

<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006' xmlns:batch='http://schemas.google.com/gdata/batch'>
    <id>https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1</id>
    <updated>2011-01-11T07:35:09.767Z</updated>
    <category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#cell'/>
    <title type='text'>A2</title>
    <content type='text'></content>
    <link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1'/>
    <link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/cells/0Aq69FHX3TV4ndDBDVFFETUFhamc5S25rdkNoRkd4WXc/od6/private/full/R2C1/1ekg'/>
    <gs:cell row='2' col='1' inputValue=''></gs:cell>
</entry>

Here, inputvalue is empty ! However, it is 300 in my xml string. Any further solution for the same ?

1
  • Please check the link, which says that I want to write back to spreadsheet. Commented Jan 12, 2011 at 13:40

1 Answer 1

1

Since the HTTP protocol only supports sending string I'm un sure if you are able to do this. But what you could try is using jQuery's ajax method and changing the method to PUT and content type and send a serialized XML.

The jQuery documentation says:

The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.

Invoke a ajax call:

 $.ajax({
  url: 'ajax/test.html',
  type: 'PUT',
  contentType: 'text/xml',
  processData: false,
  data: xmlDocument,
  success: function(data) {
    console.log(data);
  }
});

Hope it works.

EDIT: Please provide some more information/code on what you are trying to do.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks fredrik, but i want this same without AJAX.
It is the same that is given on the link I have provided.
How would you do it otherwise? "I want send PUT request with JavaScript". If you don't use AJAX it's a normal html-post. Where do you have your XML data?
Oh ! but, google doesn't support the cross domain request. If it is not possible without AJAX, I cannot write back :(
Well, from what I understand (never used the service) you parse your XML to a string. And insert in a input field. Then set method="PUT" in your form element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.