English 中文(简体)
为简单AJAX推荐建议?【已关闭】
原标题:
  • 时间:2009-03-07 20:12:25
  •  标签:

要求我们推荐或寻找工具、库或常用资源的问题,因为他们容易吸引主观化的回答和垃圾信息,因此在 Stack Overflow 上属于非主题范围。相反,请描述问题和已经采取的解决措施。

Closed 9 years ago.

我想在AJAX方面变得更聪明,但不确定应该如何做。在八年前的某个时候,我进行过一些DHTML编程 - 在这之前还没有被称为AJAX。我使用Emacs手动编码了所有的JavaScript代码,通过“Alert”进行调试。

在这个点上,我认为有一些框架可以让事情变得更好、更容易,但是哪些框架呢?从哪里开始?有推荐的吗?

  1. is jQuery indispensable? Just nice to have?
  2. What about project SACK?
  3. Firebug?
  4. any other free libraries or frameworks you recommend? or disrecommend?
  5. for a very simple project I found tons of pitfalls with FF vs IE compat. Without getting into a religious debate about who is right and who is wrong, what are some tips for navigating that minefield to produce apps that work and look mostly similar on any browser. One guy had a tip: insert * {padding:0; margin:0;} at the top of his .css stack, because FF and IE both have different default padding and margins for elements like UL OL etc. Is there a list of tips like this? Guidance?
  6. I don t have a Mac and really don t wanna incur the test cost of IE, FF, Opera, Safari, Chrome, across all the myriad versions and platforms. Hints? Is there a 80% solution here? Like if I test on FF & IE, can I guess it will work on the others?
  7. tips on tutorial sites, getting started? There s tons of info out there, which are the good places to go. In particular, because DHTML was around 10 yrs ago, my google searches are turning up some really stale information.
  8. Debugging and development tools? I found an xpath just-in-time evaluator on the web on zvon.org. It was good but not as flexible as i wanted it to be. This is something I think would be invaluable. xsl and xpath have got to be the most opaque languages I have ever used. When I started with regex, there were just-in-time regex tools available, like Expresso, etc. Those were invaluable for developing and learning regex in the early days. Last night I spent waaaay too long fiddling with an xpath expression, and I m wondering if there are similar JIT tools for xpath. And what about debugging and developing Javascript itself?

大部分我对客户端方面很感兴趣。目前对于集成客户端+服务器方法,如ASP.NET AJAX,我不是特别感兴趣。如果你告诉我有一个只针对Ruby工作的客户端AJAX框架或开发工具,我不会有兴趣。

谢谢! (Xièxiè!)

为什么我被投票反对了?这个问题问得不好吗?我觉得这个问题非常合理,难道这很不礼貌吗?

最佳回答

通常来说,它甚至比上面的ajax()函数更容易。我大多数时候只是......

$( #mydiv ).load( http://getsomehtml.php?op=loadmeup );

偶尔添加回调函数

document.body.style.cursor = "wait";
$( #mydiv ).load( http://getsomehtml.php?op=loadmeup , function() {
    document.body.style.cursor = "default";
});

我同意,jQuery是必不可少的。现在使用原始的javascript可能会遇到各种浏览器问题,是个雷区。我喜欢visualjquery.com作为一个方便的参考(但我希望Remy可以更新到1.3.2)

我无法在没有Firebug的情况下完成我的工作,因此这是必不可少的。

我在PC上使用xampplite进行测试。我使用NotePad++或Eclipse PDT 2.0进行编辑(尤其是服务器端的PHP),并使用CVS,然后我就可以正常运行了...

我进行多浏览器测试的方式是通过虚拟机。我使用Sun的VirtualBox和一个装有所有浏览器的XP虚拟机。我经常使用FF3和IE7,所以我的虚拟机中有IE6,FF2,Chrome,Opera和Safari。我有时使用Ubuntu 8.10的镜像,但并不经常。

对于正则表达式,请获取《RegexBuddy》的副本-绝对值得花40美元。

问题回答

个人认为jQuery是不可或缺的。XMLHttpRequest存在许多浏览器差异。jQuery简化了一切。这里是一个例子:

$.ajax({
    url:  document.xml ,
    type:  GET ,
    dataType:  xml ,
    timeout: 1000,
    error: function(){
        alert( Error loading XML document );
    },
    success: function(xml){
        // do something with xml
    }
});

您可以轻松地将其更改为返回JSON、HTML等。

此外,还有包装方法可大大减少参数数量,如$.load()$.post()等等。

关于浏览器的差异,我强烈建议您从类似Yahoo的重置CSS的CSS重置开始(还有其他)。

在开发方面,Firefox是标准,结合Firebug(通常还有YSlow)。HttpFox和Web开发者也是流行的插件。

  1. jQuery isn t indispensable, but it s very helpful.
  2. never heard about it
  3. I think one js framework is enough. So i recommend jQuery.
  4. CSS reset is not going to fix all compatibility issues, but it can help significantly. For ultimate css reset see Eric Meyer s CSS reset.
  5. Try http://browsershots.org/
  6. I don t have any recommendation here.
  7. For debugging javascript - firebug (firefox extension). You can also want to try fiddler to check what s passed between server and client.

For making Ajax requests, I use http://www.prototypejs.org/
For everything else, I write my own JavaScript. Even if it matter of fading a div, I still prefer to do it my way as a way of learning.

关于开始,这是我的快速教程:

new Ajax.Updater(domId, urlToAPage);

Where: domId = anything on your html page that has an id, as long as it is not an input object. urlToAPage = could be the page to contact and get the data from.

你可以把请求变得更加复杂:

new Ajax.Updater(domId, urlToAPage, {method:  post , parameters: pars} );

You can change method from post to get . Pars can be anything. Further more, it looks same for post request. So if you want to make a request to a file called hello.php and send a post parameter with two arguments, then place the response into a div called hello :

var domId =  hello ;  
var urltoPage =  hello.php ;  
var pars =  hello=1&name=hsbsitez ; 

阅读更多:http://www.prototypejs.org/learn/introduction-to-ajax

我强烈建议使用jQuery。它会让生活变得更轻松。

关于 JS 的一件事是,永远不要相信它可以正常工作。仅仅因为你使用了 JQuery 并且它在某些浏览器中正常工作并不意味着它在其他浏览器中也能正常工作。

你必须在尽可能多的浏览器和系统上尝试它。





相关问题
热门标签