Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: xmlhttp problem with different browser

  1. #1
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default xmlhttp problem with different browser

    i try to capture the return value from a server, this is how it work, is a sms API, when i want to check some sms status, need to access some url with some parameter (.aspx), the page will return some value with the same url , e.g of return value will be like 1122:12345647, when i view source , it show only the value...

    i trying to grape that value so i can store it in the database, i tried this method xmlhttp, it work in the IE, i can show the return value and store it, but it doesnt work on FF and Chrome. I try in the live server as well , it still doesn't work. Do i need any adjustment or any other method to recommend?

    Code:
    Code:
    function httpGet(theUrl)
    {
    var xmlHttp = null;
    xmlHttp = new XMLHttpRequest();
    xmlHttp.open("GET", theUrl, false);
    xmlHttp.send(null);
    return xmlHttp.responseText; 
    }
    thanks
    Last edited by keyboard; 09-28-2012 at 10:14 AM. Reason: Format: Code Tags

  2. #2
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Please use the forum's bbcode tags to make it more readable:

    for php code............[php] <?php /* code goes here */ ?> [/php]
    for html...............[html] <!-- markup goes here -->.....[/html]
    for js/css/other.......[code] code goes here................[/code]



    [Moderator's Note - No longer relevant (Formatted)]
    Last edited by keyboard; 09-28-2012 at 10:15 AM. Reason: Edit: Added Note
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That looks to me as what's called a synchronous request. It relies upon the server. If the page isn't on a server, it might not work in some browsers.

    You should be aware that a request of that type halts processing on the page until it's fulfilled. Though a little more complicated, an asynchronous request is usually a better idea.

    I would suggest using jQuery to carry out a request, but here's a good method for it using only javascript:

    http://www.dynamicdrive.com/forums/s...183#post190183

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    Last edited by jscheuer1; 09-25-2012 at 03:39 PM. Reason: add link
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for the reply, i try the guidelines and implement it into code...it work in IE, but FF and Chrome show return empty value.....the page that i try to access actually located in different domain than my domain. the sms API are third party with .aspx page. Do u think xmlhttp will work for different browser? e.g i go to this url "www.smsapi/websmsapi/creditsLeft.aspx?username=username&password=password",the same url page will return and show the credit amount. the page is just empty and show only credit left amount with the same url.

    thanks for help..
    Last edited by jscheuer1; 09-26-2012 at 10:46 AM. Reason: Format

  5. #5
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    [broken link removed] try some method here, but still dont return any value in FF and Chrome, some return as it doesnt support ajax , message. Any suggestion or basic method that can make it run on IE, FF and Chrome? thanks
    Last edited by jscheuer1; 09-28-2012 at 02:28 PM. Reason: broken link

  6. #6
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    it's a dead link
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  7. #7
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    http://www.dynamicdrive.com/forums/s...183#post190183

    sorry..thats the post i referring to....i try at local and live server...nothing work...
    xmlhttp i mention, it work for IE browser...but chrome n ff show return nothing... please guide me....
    the url i need to access is .aspx file, it will return some value, this file is store are different domain.

    Any way can show that IE , FF and chrome can capture return value from different domain?

    thanks

  8. #8
    Join Date
    Sep 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <p><b>SMS.</b><b><br />
      </b>
    </p>
    <hr/>
    <p>&nbsp;</p>
    
    {literal}
    <script language="javascript">
      function httpGet(theUrl)
      {
        var xmlHttp = null;
        xmlHttp = new XMLHttpRequest();
        xmlHttp.open("GET", theUrl, false);
        xmlHttp.send(null);
        return xmlHttp.responseText;
      }
    	
    </script>   
    {/literal}
    
    {php}
    global $Q;
    if ($Q->get_permission('crm_sms','readcontent') == '1')
    {
    {/php}
        
        {foreach from=$sms_account item=type }
        Account : {$type.name} <br />        
             {literal}
             <script language="javascript">
    		 
             document.write('Credit(s) left : '+httpGet("http://globalsms.com.my/websmsapi/creditsLeft.aspx?username={/literal}{$type.user}{literal}&password={/literal}{$type.pass}{literal}")+'.0');
    		 </script>
    		{/literal}
    <br/><br />
    	 
        {/foreach}
    {php}
    
    }
    else
    {
    echo 'Permission not allowed.';
    }
    {/php}
    those are the code i use, is a tpl page....and i try it it local and live server also.....the sms page are from different domain.

    thanks
    Last edited by keyboard; 09-28-2012 at 10:16 AM. Reason: Format: Code Tags

  9. #9
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by daytonatkf View Post
    ...the page that i try to access actually located in different domain than my domain.
    you should be aware that this usually prevents ajax calls, due to security issues. Almost all of javascript relies on a "same-origin policy" (dealing with only the current domain).

    Two options I see:

    1) See if your third party API will support cross-origin resource sharing. Mozilla has a good explanation of CORS.

    2) Configure your server to send an HTTP request to access the API. With PHP, this can be done via the cURL extension. I know it is possible to achieve in most server-side web languages, though I don't know how it works in other languages (are you using a server-side language now? you mentioned the API was an asp site, but now that I re-read your posts, it seems your site might be static [client-side scripting only]...?).

    Once you make the API call from your server, you page can access the results via ajax normally.

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    AJAX generally won't work on a page from another domain. And it's technically illegal to grab another domain's content as your own. It's copyright infringement. That is unless the content you're grabbing is also yours, just happens to be on a different domain or you've subscribed to it legally for use on your site as opposed to for personal use.

    But AJAX alone still cannot do this, you would need some server side code to first grab the external domain's page's content to a server side file and/or server side script. From that script and/or file - now on your domain, you can import the content via AJAX to a page.

    If that's what you're already doing, it may just be a matter of timing. Is the external content transferred to your domain before the AJAX request for it is executed . . . If not you need mechanisms in place to make sure that it is or a way of polling it to see when it arrives.

    I'll have a look at your code and see if it reveals anything else to me.

    OK I did -

    It looks like you're using php. If so you could try a file_get_contents. It too can be limited to same domain, but not always. That depends upon your server's settings. It's ultimate success, assuming your server allows it, depends upon the external domain not blocking it.

    The bottom line though, if this is an API service, why not just use the API, why complicate matters with AJAX?
    Last edited by jscheuer1; 09-28-2012 at 02:51 PM. Reason: looked at code
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Browser Problem
    By Webiter in forum JavaScript
    Replies: 4
    Last Post: 08-27-2011, 02:58 AM
  2. IE 7 browser problem
    By robin9000 in forum Other
    Replies: 1
    Last Post: 04-01-2009, 01:15 AM
  3. DOM alternative to document.write(xmlhttp.responseText)
    By molendijk in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 08-21-2008, 11:27 AM
  4. Replies: 14
    Last Post: 05-06-2006, 11:09 AM
  5. hi problems with xmlHttp request
    By tyllerdurdent in forum Other
    Replies: 0
    Last Post: 03-27-2006, 03:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •