简体   繁体   中英

Submitting form without refresh

I am retrieving Google's weather API XML and using PHP. I'm retrieving the weather for any searched city.

Now, this "app" is under a tab and whenever I submit the form it refreshes and I want to prevent this.

Is it possible? This will be implemented in a dashboard - thats the reason I want to prevent the refresh.

This is what I mean: http://www.screenr.com/30As

The entire code is here: http://jsfiddle.net/ZshpF/ Simply, copy paste the code in a php file and it will work.

You'll want to use AJAX . Since you mention jQuery in the tags, it has a very handy function for making the call to the server. But making the call from the JavaScript is only half the story, you'll also need something on the server listening for that call. It would essentially be another PHP script which acts as a page in and of itself, but would return data in the form of (most likely) JSON instead of HTML. It's not meant to be human-readable, but rather to be a sort of web service for your JavaScript code to use.

You can find a simple example here .

我认为您可以使用jQuery ajaxForm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM