Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:31:52+00:00 2026-06-18T10:31:52+00:00

I have a javascript code that calls a function of a PHP api to

  • 0

I have a javascript code that calls a function of a PHP api to insert a row in my database.

var url = 'http://myapi/OfertasVentaOnline/api.php?method=update&function=categoria&id='+id+'&idCategoria='+id_categoria+'&descripcion='+descripcion+'&format=json';


    $.getJSON(url, function (data){     

    });   

a sample of this url:

"http://myapi/OfertasVentaOnline/api.php?method=create&function=categoria&id=9999&idCategoria=3&descripcion=test%new%category&format=json"

in the url i replace the spaces for % in the descripcion parameter, as shown here the url is created correctly.

then I got my api who gets the call and decodes it. in the function that i use to decode and get the parameters:

$descripcion_cool = str_replace("%"," ",$_GET['descripcion']);

echo utf8_decode($descripcion_cool);

$query = 'INSERT INTO `Categorias`(`idCamping`, `idCategoria`, `descripcion`) VALUES (
                    "'.mysql_real_escape_string($_GET['id']).'",
                    "'.mysql_real_escape_string($_GET['idCategoria']).'",
                    "'.mysql_real_escape_string($descripcion_cool).'")';

this outputs this:

test new?tegoryINSERT INTO `Categorias`(`idCamping`, `idCategoria`, `descripcion`) VALUES (
                    "9999",
                    "3",
                    "test new�tegory")null

as you can see, php add some special characters to the url parameters. What am i doing wrogn ? thanks

PD: in my php file i tried to add:

header('Content-type: text/plain; charset=utf-8');

but it keeps doing the same.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:31:53+00:00Added an answer on June 18, 2026 at 10:31 am

    Assuming you’re sending param values having spaces, you are encoding it by replace space with % . Actually, you don’t have to do that. You can use encodeURIComponent() method if you want to encode params/quesrystings being passed over. And if you want to encode url, then use encodeURI()

     description = encodeURIComponent(description);
    
    var url = 'http://myapi/OfertasVentaOnline/api.php?method=update&function=categoria&id='+id+'&idCategoria='+id_categoria+'&descripcion='+descripcion+'&format=json';
    
    
    
        $.getJSON(url, function (data){     
    
        });   
    

    This will safely enocode url.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have php code that calls a javascript function: onclick='fightit(0,0,0,0,0)' Here is the javascript
Hello I have a php code which by echo calls the javascript function expand(txt)
I currently have some JavaScript code that calls a .php file to send me
I have seen Javascript code that uses parenthesis immediately after a function's closing curly
I have the following Javascript code that works perfectly: $(document).ready(function() { $(#Select1).setDefault(); $(#Select2).setDefault(); $(#Select3).setDefault();
I have a php page with the follow javascript code in it: $(#saveButton).click(function() {
I have the following function in javascript that calls the ajax which calls the
I have a javascript variable that is created in php echo var.$locallist.=.create_js_variable($locallist,$db2_list_all,'db2'); and it
i have a function that calls javascript:del_release_comment(10,12); from the page, if the user has
I have code that looks something like this in javascript: forloop { //async call,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.