0

I am trying to pass the time zone parameter in a Ajax request

Like

 alert(meeting_time);
        alert(meeting_timezone);
    $.ajax({ 
        type: "GET",  
        url: "http://webfaction/UI/user/joinmeeting.php",  
        data: "user_names="+ user_names + "&image=" +file+"&duration="+ duration +"&user_name="+ user_name + "&meeting_id=" + meeting_id + "&moderator_password=" + moderator_password +"&attendee_password=" + attendee_password +
        "&meeting_time=" + meeting_time + "&meeting_timezone=" + meeting_timezone + "&meeting_sms_no=" + meeting_sms_no + "&meeting_logout_url=" + meeting_logout_url +"&meeting_maxp=" + meeting_maxp +"&meeting_name=" + meeting_name ,
        success: function(json){  
               alert(json);
              $('#show_ajax').hide();
            if(!json.error) location.reload(true);

        },

Now my problem is before ajax request

alert(meeting_timezone);  is printing  `GMT +8.00`

but on the joinmeeting.php page

   $meeting_timezone = $_GET['meeting_timezone'];   

   print $meeting_timezone;

the above print statement is printing the value GMT 8.00

(+ sign is not printing here)

Please tell me how to fix this problem ?

user1667633
  • 4,449
  • 2
  • 16
  • 21

3 Answers3

0

That's a known situation while using POST and GET methods, your + signs will be converted to space. The right way to pass data through POST or GET is using encodeURIComponent in JavaScript.

For example in your case, do this before sending:

meeting_timezone = encodeURIComponent(meeting_timezone);
Night2
  • 1,168
  • 9
  • 18
  • thanks man even i also found the same solution but one more thing can i put parameter string inside URIComponent ? – user1667633 Sep 15 '12 at 06:46
  • You can put any string you are passing in that function, but don't put whole of URL in it, use it like this: 'url.php?a=' + encodeURIComponent(SOMETHING) + '&b=' + encodeURIComponent(SOMETHINGELSE) Take a look at the link @YAAK provided in his answer for more info ... – Night2 Sep 15 '12 at 07:04
0

It will help if you encode your URL in JavaScript by

encodeURIComponent(uri)

Like this:

data: encodeURIComponent(("user_names="+ user_names + "&image=" +file+"&duration="+ duration +"&user_name="+ user_name + "&meeting_id=" + meeting_id + "&moderator_password=" + moderator_password +"&attendee_password=" + attendee_password +
        "&meeting_time=" + meeting_time + "&meeting_timezone=" + meeting_timezone + "&meeting_sms_no=" + meeting_sms_no + "&meeting_logout_url=" + meeting_logout_url +"&meeting_maxp=" + meeting_maxp +"&meeting_name=" + meeting_name )

Also take a look at this question:

How to encode a URL in Javascript?

might be useful

Community
  • 1
  • 1
YAAK
  • 328
  • 1
  • 14
0

Instead of specifying the data: parameter as a string, use an object:

data: { user_names: user_names,
        image: file,
        ...
        meeting_timezone: meeting_timezone,
        ...
      }

jQuery will then take care of converting it to a query string properly.

Barmar
  • 741,623
  • 53
  • 500
  • 612