1

Hi everyone I amsending one string in post method for that I have following code:

function sendText(txt)
    {

        var internetUrl="http://myURL/";
        var url =internetUrl+ encodeURI("customer/Ri_logon.asp?requestString=");
        var parameters = 'manish|^test1234|^|^X|^11111985|^1.0|^|$';
        alert(url);
        alert(parameters);
        txt = parameters;
        var xhr = new XMLHttpRequest();
        xhr.open('POST', url, true);
        xhr.onload = function(e) {
          if (this.status == 200) {
            console.log(this.responseText);
            alert(this.responseText);
          }
          alert("!!!"+this.status);
        };

        xhr.send(txt);
      }

    </script>

I got error at xhr.send(txt); errorr is: ABORT_ERR: XMLHttpRequest Exception 102: The user aborted a request in synchronous requests at xhr.send(txt);same code runs on blackberry ,symbian and android. But on Bada I got error.

In manifest.xml I had given Privilege as:

<Privileges>
    <Privilege>
        <Name>WEB_SERVICE</Name>
    </Privilege>
    <Privilege>
        <Name>SYSTEM_SERVICE</Name>
    </Privilege>
    <Privilege>
        <Name>HTTP</Name>
    </Privilege>
    <Privilege>
        <Name>NET</Name>
    </Privilege>

In Thanks in advance. Any help will be appreciated.

PPD
  • 5,660
  • 12
  • 52
  • 86

1 Answers1

0

Your question is tagged with jQuery; why aren't you using it?

$.post(url, txt, function(data) { console.log(data); });

My experience is to never use XHRs in your code. Different browsers all have different implementations and the API itself is pretty rigid and verbose (in my humble opinion).

  • I want to run same code on Blackberry5 also, and it dies not support ajax, but support XMLHttpRequest, Therefore I am using XMLHttpRequest. – PPD Aug 09 '12 at 12:03
  • And therefore you risk breaking compatibility with every other browser. I see two obvivous solutions: 1. Use browser/feature detection to detect Blackberry 5 and revert to the XHR code. Browser detection is a sin, but goodness knows how many sins were committed in writing the BB OS. 2. Drop support for BB 5 (or re-structure your page without AJAX). On one of the projects I worked on we couldn't for the heck of it get IE to work on the mobile site, so we decided to drop Windows Phone and IE Mobile support completely. It's a very small % of your user base, so the harm is minimal (hopefully). –  Aug 09 '12 at 12:46