开发者

After form submit, add data without refreshing?

I have been looking around for a few hours trying to figure out how I am going to do this. I have ZERO experience with jQuery and I could never get it to work for me.

I basically have a Support system where a user can add replies to the tickets. Instead of POSTING the data the the same page and refreshing it, I was thinking after submitting it have it popup in the conversation.

I store all my data in a mySQL database, if that helps. 开发者_开发知识库So after submit, I get a mySQL refresh would do the trick? Again, I am a novice in this.

Just need a good nudge in the right direction. Some source code and links would be awesome too.

Thanks,

Coulton


jQuery ajax is your friend: http://api.jquery.com/jQuery.ajax/

This will send data to the server asynchronously, and execute success or error depending on how the server responds. All of this is done without a page refresh. Whatever the server (PHP) returns from its method will be given to jQuery when it's done, whether it be JSON, HTML, XML, and so on:

var request = $.ajax({
    url: '/MyPHPAction',
    data: myFormValues,
    type: 'post',
    dataType: 'json' // or html, etc.
});

request.success(function(response, textStatus, jqXHR) {
    // in here, response is what was returned by PHP
});

request.error(function(jqXHR, textStatus, errorThrown) {
    // in here, you can get detailed information on why the request would have failed
});


You want to use Ajax. It is a very rich technology, and jQuery is a great Ajax library. You don't sound familiar with this, so google Ajax and get familiar as there is a lot of code you have to look at, too much to post here. I even wrote an article about it. I can't say it's the best, but maybe it will help a bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜