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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    jquery/ajax json data function not working

    Hi Everyone, I have the following function it suppose to talk to another server retrieve the json data and display it the problem is the function is not even initiating a query I'm I doing something wronge? the code is uploaded into the apache tomcat server and I used wireshark for traces and there are none on the http port here is the code

    Code:
    $(document).ready(function () { var home_add = 'http://myweb.net:3300/gateway'; $('#handshake').click(function () {     alert(" sending json data");     $.ajax({                 /* start ajax function to send data */         url: home_add,         type: 'POST',         datatype: 'json',         contanttype: 'text/json',         async: false,         error: function () { alert("handshake didn't go through") }, /* call disconnect function */         data: {             "supportedConnectionTypes": "long-polling",             "channel": "/meta/handshake",             "version": "1:0"         },         success: function (data) {             $("p").append(data + "<br/>");             alert("successful handshake")         }     });  });

  • #2
    Regular Coder
    Join Date
    Dec 2007
    Posts
    137
    Thanks
    1
    Thanked 21 Times in 21 Posts
    Couple things

    First you have an in your javascript code. It is missing a ")" after your curly braces on your last line.

    Secondly, I assume you are also including the jquery library, as this is jquery code, otherwise it won't run if you don't include/src it.

    I ran your code with the included jquery library and adding the missing ) and it seemed to run OK, but it would not connect to your script page as I received a permission denied error on your gateway page.


    Code:
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
            <script type="text/javascript">
                $(document).ready(function () {
                    var home_add = 'http://myweb.net:3300/gateway';
                    $('#handshake').click(function () {
                        alert(" sending json data");
                        $.ajax({
                            /* start ajax function to send data */
                            url: home_add,
                            type: 'POST',
                            datatype: 'json',
                            contanttype: 'text/json',
                            async: false,
                            error: function () {
                                alert("handshake didn't go through")
                            },
                            /* call disconnect function */
                            data: {
                                "supportedConnectionTypes": "long-polling",
                                "channel": "/meta/handshake",
                                "version": "1:0"         },
                            success: function (data) {
                                $("p").append(data + "<br/>");
                                alert("successful handshake")
                            }
                        });
                    });
                })
    
            </script>


  •  

    Tags for this Thread

    Posting Permissions

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