Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    907
    Thanks
    301
    Thanked 2 Times in 2 Posts

    Question jQuery - Requesting data from webservice

    Hi

    I am trying to get values from a third party webservice. When I resolve the API link directly in my browser, it works fine and shows result (in json format)

    Code:
    API Link: http://outlineme.com/test/index.php
    
    Result: {"result":true,"time":"2013-04-28 08:19:10"}

    But when I run the same code using jQuery AJAX (with JSONP datatype) it does not show up anything. My code is below:

    Code:
    $(document).ready(function(){
    
        $.ajax({
          url: 'http://outlineme.com/test/index.php',
          data: "",
          type: 'get',
            dataType: 'jsonp'  ,
          success:function(result){
    
            alert(result.time);
        }});
    
    
    
    
    
    });


    JS Fiddle: http://jsfiddle.net/WgZ9c/1/


    Can someone pls tell me what am I missing here?


    Many thanks

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,386
    Thanks
    11
    Thanked 565 Times in 558 Posts
    Maybe (and probably) the API does not support JSONP?

    JSONP will have to be handled differently. Instead of outputting raw JSON, the server should output Javascript with a call to a JSONP callback which will trigger the success method of your script.

  • Users who have thanked devnull69 for this post:

    phantom007 (04-29-2013)

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    907
    Thanks
    301
    Thanked 2 Times in 2 Posts
    What should the output of JSONP look like?

    An example pls?


    Thanks

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,273
    Thanks
    10
    Thanked 581 Times in 562 Posts
    you need either jsonp or to enable cors on the API server.

    jsonp is just json in parens with a word in front:

    Code:
    {"a":1}
    becomes
    Code:
    callback({"a":1})
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    phantom007 (04-29-2013)

  • #5
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    907
    Thanks
    301
    Thanked 2 Times in 2 Posts
    Many thanks for your inputs.

    I can do now this using jQuery. Can you also please tell me how to do this using core JS (not any library)



    Mny thanks in advance

  • #6
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    907
    Thanks
    301
    Thanked 2 Times in 2 Posts
    Pls can someone help me here?

  • #7
    rff
    rff is offline
    New to the CF scene
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll want to use the xmlhttp object.

    http://www.w3schools.com/ajax/ajax_x...quest_send.asp


  •  

    Posting Permissions

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