0

Hi All,

I have a application , which onclick of submit takes content in textarea and do some back end stuff and finally opens a .html in a iframe.

My problem is, the .html in iframe should change on each submit button in coresponding to the content in the textarea.... but its not, can anybody a suggest a solution for this?

           function submit() {
                var textAreaContent = $("#content").val();
                   var content = textAreaContent.substr(textAreaContent.indexOf('\n'),textAreaContent.length);
 alert(content);
                $.ajax({
                    type: 'GET',
                    url: 'submit.php?data='+content+'',
                    contentType: 'application/json',
                    dataType: 'json',
                    success: function(response) {
                        alert("Sucess");
                    },
                    error: function(response) {
                        alert("Error");
                        alert(response);
                    }
                });

 document.getElementById("ChromatinModel").src = "http://dna.engr.latech.edu/~kpc009/ICMGB/ICM/chromatin.html";
            }
        </script>


            <iframe id="ChromatinModel" width="505" height="500" ></iframe>

Thanks,
Priya

2
Contributors
1
Reply
6
Views
3 Years
Discussion Span
Last Post by LesF
0

I think you should put the content data into the 'data' parameter in the ajax call, instead of adding it to the URL, such as:

url: "submit.php",
data: "{'content':'" + content + "'}",

but it gets a bit tricky with the formatting of the value for the data parameter; the value should be a serialized JSON string, and the contents of a textarea can of course include quote characters etc. I sometimes use a stringify function to serialize an array of data to be submitted, and do something like:

var myParams = {param1: value1, param2: value2};
$.ajax({
  type: 'GET',
  url: 'submit.php',
  contentType: 'application/json',
  data: stringify(myParams),
  dataType: 'json',
  etc...

Depending on the version of jQuery or whatever libraries you are using, or versions of browser you are targetting, the stringify function or other JSON serialisation methods may be available already.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.