views:

61

answers:

3

I have a button on a page which when clicked makes a ajax request. Viewing the response in firebug and looking at the page it basically returns the exact same page in the browser with the addition of an image and some text wrapped in a table. How would I check this response and see if it contains this text and image and if it find it redirect to another page.

The redirect I pretty much have

location.replace('http://www.redirectpage.com');

But I do not know how to target and check the response.

I want to so something like this in either Jquery or javascript.

If response has text contains "Please fill in" and contains /a/a/i/error_alert.gif then redirect to

http://www.redirectpage.com

Sorry for my noobness, any help would be appreciated!!!

+3  A: 

Like this?

if(response.indexOf('Please fill in') != -1 && response.indexOf('/a/a/i/error_alert.gif') != -1)
Can you put this in with the redirect so I can test it?cause when I put this code in with the redirect it breaks.
if(response.indexOf('Please fill in') != -1 }
http://www.asnlaundryparts.com/Articles.asp?ID=177Here is an example page that I want to check for this and redirectClick on the add to cart button
That is not really a question, but the page you linked to does not seem to have that code I gave anywhere when you click the "add to cart" so I am not sure what you are trying to do.
When you click on the button calls the addToCart2 ----- function addToCart2(form, button) { var softAdd = true;var product_id = form.elements['ProductCode'].value;var qstr;var bttnName = button.name;button.disabled = true;if (form.elements['ReturnTo']) {form.elements['ReturnTo'].value = "";}qstr = serialize(form, bttnName + '.x', '5', bttnName + '.y', '5');sendAjax('POST','/ProductDetails.asp?ProductCode=' + product_id + ' button.disabled = false; return false; }
I am trying to check the response to which to me seems to be the whole page returned with the image your see and the text "# Please fill in the Pins field ." So I want to be able to check for this and if it is returned then do a redirect. I thought by giving you the link to the actual page it would make more sense but I am afraid it only made it worse to understand.
A: 

To search in XML or HTML contents you should use some XPath library.

despart
A: 
if (text.indexOf("/a/a/i/error_alert.gif") > -1 
    && text.indexOf("http://www.redirectpage.com") > -1) {
      // matches -> redirect to http://www.redirectpage.com
} else {
     // redirect to default location 
}
​
galambalazs