...

View Full Version : jquery/ajax json data function not working



lava_saleem
12-20-2010, 08:43 PM
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


$(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") } }); });

pigpen
12-21-2010, 08:44 PM
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.



<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum