Posts tagged ajax

How to make cross-domain ajax request using jsonp & jquery

1

As you may know AJAX request cant be done across domain (even across subdomain). This is a security feature but sometimes It can pretty usefull to make call between domains.

Luckily for us AJAX allows us to make cross domain request for javascript contents. That is how JSONP works, basicly instead of passing plain json you pass json inside a javascript function.

I’m going to show you how you can do this very easily using jQuery.

first of all make the call using jquery.

$.getJSON("http://someurl/somepage.php?jsoncallback=?",function(data){
  alert(data.msg);
});

As you can see we have to set jsoncallback=? in the url for this to work.

Now In your php file.

<?php
	$array = array("msg"=>"hello"); //some bogus data
	echo $_REQUEST['jsoncallback']."(".json_encode($array).")";
?>

The output will be something like :

jquery65456456456({“msg”:”hello”})

As you can see It now looks like a javascript function.

That’s all there is too it !

Share

Related Posts:

How to install anyterm on ubuntu Karmic Koala

11

Hello everyone,

I had to install anyterm on a fresh karmic koala yesterday but i’ve ran into so many problems that I decided I’ll write a simple tutorial about this subject.

Anyterm is a software that allows you to acces a terminal over http(s) protocol, so it allows you to bypass most proxys.

For more info on anyterm please visit the official website at http://anyterm.org/

This tutorial will explain how to compile from the SVN source 1.1.29 but may be slightly diferent if you are trying to use another version.

(more…)

Share

Related Posts:

Ajax notification messages MSN style

14

Hello everyone,

today i will discribe a simple way to do notification messages the same way that msn shows that you have a new message.

The CSS is not meant to be beautiful but just enought for you to understand and tweak it as you wish.

Note : This script uses jquery

You can see a demo here

(more…)

Share

Related Posts:

form submit via Hidden iframe (A.K.A Fake Ajax)

0

Today, I wanna share with you a way to submit forms using a ajax look & feel altought it’s not really ajax.

The question you might ask is :

why should I use this method instead of real ajax ?

Well they’re is numereous answer to that but one good reason it that is doesnt require any type of ajax libs and you can start using it even if you never used ajax before.

(more…)

Share

Related Posts:

Go to Top