0

我尝试了很多方法来访问网站 ajax 功能。这是代码:

$.ajax({
    type: 'POST',
    url: 'sched', 
    so on and so fourth..
});

注意:在 url 中有一个 url 参数,名为sched. 显然,如果我在自己的服务器或网站上运行它,这将不起作用。有什么方法可以让我知道这个 url 的根地址吗?比如example.com/sched?谢谢

4

1 回答 1

0

AJAX does not support requests on other domain. This leaves us with two choices

  1. Fetch response from a server-side code using HttpWebRequest or the likes
  2. Use JSONP. If the other domain supports JSONP callbacks.

Using JSONP is simple and this has been clearly explained in other post on Stackoverflow. You may use method #1 or method #2, both in same question.

If we want to fetch data from other domain which does not support JSONP, then we're left with only option to use server-side code.

Hope this helps!

Vivek

于 2013-03-31T08:49:11.417 回答