2

On my webpage I have a textarea where admins can enter html and then save it to display on the page for non-admins. I tried transferring the saved html text to the php just like any other variable I have every sent over ajax, but for whatever reason, html is not allowed to be sent as a GET parameter. My ajax reguest is below

function saveNotesToDBAjax(textBoxValue, buildName){
var urlString = "saveNotesToDBAjax.php?Build=" + buildName + "&Text=" + textBoxValue;
function testAjax() {
  return $.ajax({
      url: urlString
  });
}
var promise = testAjax();
promise.success(function (data) {
  //alert(data);
  console.log(data);
});}

The above variable "textBoxValue" is the variable that will hold html. Is there anyway to get around this problem? Also, the error my console is showing says "GET (then lists my url) 403 error"

Thanks in advanced!

4
  • 2
    Is the text URL-encoded? It definitely should be if it's being sent on the query string like that. Otherwise, you might send the text as a form value instead. Commented Jul 27, 2015 at 16:44
  • 1
    beware that GET has character length limits...better to post if it is long. Let jQuery encode it for you as object Commented Jul 27, 2015 at 16:49
  • According wikipedia A web server may return a 403 Forbidden HTTP status code in response to a request from a client for a web page or resource to indicate that the server can be reached and understood the request, but refuses to take any further action. So the problem is for sur in the format of your query string, use charlietfl and david advices => use POST Commented Jul 27, 2015 at 17:04
  • Thank you all! I changed it to a POST and everything works as desired! Commented Jul 27, 2015 at 18:59

1 Answer 1

1

Try:

function saveNotesToDBAjax(textBoxValue, buildName){
    $.ajax({
        type: "POST",
        url: "saveNotesToDBAjax.php",
        data: { 'Build': buildName, 'Text': textBoxValue },
        success: function(data){ console.log(data); }
    });
}

Remember to switch from $_GET[] to $_POST[].

Sign up to request clarification or add additional context in comments.

Comments

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.