简体   繁体   中英

Get response from ajax and parse the response with html on webpage

I need to run a search using Ajax, such that the response I get from Ajax (should not contain HTML, it should only contain data) is fetched on webpage and then parse that response with HTML on the page and display.

I want to know can it be done, if yes then how to do it. Also is it going to make process run faster or consume less resources on server?

Since you have made no attempt to try to code this, I will give you a couple pointers.

1.) It is very possible, I do it on login forms.

2.) Post data to a external page, then encode the response on that page to an array in JSON. echo out the JSON on the external page.

3.) After your ajax post is finished, you can carry out a function similar to this:

function(data){alert(data.given_name_on_external_page)}

or something similar. Once you google around for Ajax form examples you should be able to grasp a little better.

4.) Now for displaying this on a web page, it is fairly easy.

HTML

<div id='response'></div>

Javascript

function(data){document.GetElementById('response').html=data.data};

That should be enough for you to understand what needs to be done, I will leave the rest to you and your ability to use google :).

在JQUERY中使用转义和load()功能

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