0

I am trying to pass multiple values through query string, and I have done a lot and able to pass the values which are of single word to php page using jquery. But when I am trying to pass the name of User say "Vishal Deb" it is not passing the whole name. I checked in Fire Fox Web console it passing only first half the name means only "Vishal" is passed. Here is my jQuery Code

$(".searchBtn").click(function(){
    showLoader();

    $('#sub_cont').fadeIn(1500);
    $("#content #sub_cont").load("search.php?name=" + $("#name").val() + "&admission_year=" + $("#addyear").val() + "&branch=" + $("#branch").val() + "&course=" + $("#course").val() + "&cclass=" + $("#cclass").val()+ "&fathername=" + $("#fathername").val()+ "&ph1=" + $("#ph1").val()+ "&dura=" + $("#dura").val(), hideLoader());
});

And this what I am getting in Fire Fox Web Console after enter my as Vishal Deb

[15:01:44.149] GET //localhost/daponlinein/admin/search.php?name=%27vishal [HTTP/1.1 200 OK 1044ms]

Why this problem is coming can any one guide me. Thank you

peko
  • 11,267
  • 4
  • 33
  • 48
user2241865
  • 113
  • 4
  • 14
  • 1
    Try to html encode the parameters. http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding – guruprasath Apr 11 '13 at 09:47
  • 1
    Use `encodeURIComponent` to encode values properly before inserting them into a URL context. – CBroe Apr 11 '13 at 09:48

2 Answers2

2

A space is an invalid character in a URL query string value. You have to encode it to %20.

So your resulting URL should look like:

search.php?name=vishal%20deb

Don't forget to adjust your PHP code to both serialize and deserialize that properly.

Richard Neil Ilagan
  • 14,627
  • 5
  • 48
  • 66
0

Encode it as:

var name = encodeURIComponent($("#name").val());
Arvind Bhardwaj
  • 5,231
  • 5
  • 35
  • 49