Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-20-2010, 07:43 PM   PM User | #1
lava_saleem
New to the CF scene

 
Join Date: Oct 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
lava_saleem is an unknown quantity at this point
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")         }     });  });
lava_saleem is offline   Reply With Quote
Old 12-21-2010, 07:44 PM   PM User | #2
pigpen
Regular Coder

 
Join Date: Dec 2007
Posts: 137
Thanks: 1
Thanked 21 Times in 21 Posts
pigpen is on a distinguished road
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>
pigpen is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, jquery, json

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:32 PM.


Advertisement
Log in to turn off these ads.