0
$('#participate').click(function(){

 var content = $('#item-content-text').html();

  VK.api('wall.post',{ message: content}, function(data) {
      if (data.response) { // если получен ответ
              //message send
      }
      else{    
        // error
       }
    });

})

So I'am clicking on a button an then I get some page html content, the question is:

How can I send many html content Via GET, maybe is there an option by sending content by loop, but how to do that?

i think something like this:

for(var i = 0; i < content_array.length; i++){
     VK.api('wall.post',{ message: content_array[i]}, function(data) {
         if (data.response) { // если получен ответ
            //part of html sended
         }
         else{
            // error
         }
        });
}

but how to split a big html content by parts?

PS: if someone know the (API VK) that there are no options to send that data Via POST, thats is why I'am using GET...

Niks Jain
  • 1,617
  • 5
  • 27
  • 53
  • use [str_split](http://www.php.net/manual/en/function.str-split.php) to split the string up into different parts? Will VK even let you make several http gets to the same wall post? – Pastor Bones Nov 03 '12 at 08:42
  • But i don't know how can I post much text in one request?, is there a way?, i get an error that the request is too large if do this on one request – BubbleStalker Nov 03 '12 at 08:45
  • is there an option to split that in javascript?, because I use only javascript.. – BubbleStalker Nov 03 '12 at 08:46
  • heh, sorry...had php on the brain. I created an answer with a function to quickly split a long string into _n_ size chunks – Pastor Bones Nov 03 '12 at 08:53

1 Answers1

0

Split the string up into chunks

var chunkStr = function(str, chunkLength) {
    // Split at the end of a tag
    return str.match(new RegExp('.{1,' + +chunkLength + '}', 'g'));
}

var newstring = chunkStr( oldstring, 128 );
Pastor Bones
  • 7,183
  • 3
  • 36
  • 56
  • what about html tags?, if i get $('div_content').html() - it returns me an entire html of the article, so the i need to send that article by parts, how to split that? – BubbleStalker Nov 03 '12 at 09:04
  • most servers restrict the length of get requests to 255 bytes. Trying to split on the end of a tag might be longer than that, but check the edit I just made. – Pastor Bones Nov 03 '12 at 09:10
  • var html = "
    hello

    this is sparta

    ну да это спарта
    "; var splited = chunkStr(html, 128); alert(splited); - was triyn to do this, but its return me null
    – BubbleStalker Nov 03 '12 at 09:46