Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ajax - return only part of responsetext

The below is just a bit of my ajax code, at the moment my variable 'resp' is returning an entire response from test.php. Is there any way I can just return the responseText between a specified tag? ie. just get back the responseText of the html inside test.php's div of id="xyz"?

var loc="test.php?myinput=apple";
ajax.onreadystatechange=function() {
        if (ajax.readyState==4  && ajax.status == 200) {    
            var resp =  ajax.responseText;
        }
    }
ajax.open("GET",loc,true);
ajax.send(null);
like image 484
toop Avatar asked May 10 '11 12:05

toop


People also ask

How to return Ajax response data?

What you need to do is pass a callback function to the somefunction as a parameter. This function will be called when the process is done working (ie, onComplete): somefunction: function(callback){ var result = ""; myAjax = new Ajax.

What is jqXHR in Ajax?

The jqXHR Object. The jQuery XMLHttpRequest (jqXHR) object returned by $. ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method.

What is responseText in jQuery?

The responseText method is used for all formats that are not based on XML. It returns an exact representation of the response as a string. Plain text, (X)HTML, and JSON are all formats that use responseText.


1 Answers

You could use jquery shorthand function load() to do this in a swift

$('#result').load('test.php' #container');

here result is the div where you want to place the response text and container is the your specified source element location of test.php

is this what you want?

like image 193
Dipesh KC Avatar answered Sep 21 '22 13:09

Dipesh KC