0

I have the following lines of code:

var search = $("#txtSearch").val();
search.replace(" ", "%20");
$(".header").html("/Parts/Search.php?type=" + $("input[name=type]:checked").val() + "&q=" + search);
$(".main-content").load("/Parts/Search.php?type=" + $("input[name=type]:checked").val() + "&q=" + search);

I know there is a textbox with the id specified in the first line, and two inputs of type radio with the name set to type. The value passed for type is either postcode or normal. The correct output (as far as I can see) is being displayed in any elements satisfying the .header selector. However the page is not loading into .main-content. There is another page, called Search.php, to which the user is taken if JS is disabled (i.e. there is a submit button which submits to /Search.php through the GET method - this disappears and a Search link appears if JS is enabled). If this page has the two querystring parameters specified then it will include /Parts/Search.php. This works fine - it reads the querystring from the parent (root level) Search.php. I dont get why it wont work with jQuery though. Does anyone have any ideas?

Thanks in advance,

Richard

PS I have also tried attaching the value of the search box on the end of the URL, without storing it in a variable and then replacing the space... this didnt work either.

3
  • 1
    I have read it like 5 times now and I still can't understand what's the fault here. ;) Can you include clearer scripts? I mean the script you have provided is so small that I'm not sure what to assume. Commented Oct 8, 2010 at 2:58
  • A good example of a page which loads wrongly using jQuery is php page: /Search.php?type=PostCode&q=DT11%209HG, which outputs 3 results within 25 miles, and jQuery: /Parts/Search.php?type=PostCode&q=DT11 9HG. I have tried it with and without the space (in the jQuery querystring) replace with %20... I just dont get why... Commented Oct 8, 2010 at 3:02
  • Found the bugger - it was the replacement line. It was just sending DT11 as the postcode (which my app cannot cope with, yet) because there was a space there. The line search.replace(" ", "%20"); does nothing - it must be search = search.replace(" ", "%20");! Reigel - I have upped your comment for trying... Commented Oct 8, 2010 at 3:10

1 Answer 1

2

Line 2 looks suspicious to me. replace returns a value. Try this.

search = search.replace(" ", "%20");
Sign up to request clarification or add additional context in comments.

2 Comments

Ha, oops, after reading all the comments I see you did note this. But just wanted it to be more obvious.
A bit late but +1 for trying to help.. everything was done by comments so there was no answer to mark as correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.