开发者

Sending iframe tag to Mysql via Jquery ajax request

-- EDIT --

Solved by using JSON dataType.

-- QUESTION --

Hello,

I am trying to send iframe video embed code to db. I finally found javascipt's escape() command and it was working if I send only the embe开发者_高级运维d script. Later, I tried to add embed code after some text and it neither gives an error at ajax or mysql nor adds the post.

What is the problem here? Do you have another solution for sending embed code without corruption instead of javascript's escape()? Can I do something with php?

Thank you,

I am getting content from page with var content = escape($('#textarea').html()); and sending with ajax. If I would use JSON type, will it send without corruption?

Sample iframe:

<iframe title="YouTube video player" width="540" height="435" src="http://www.youtube.com/embed/8ImAG94lSOE?rel=0&amp;hd=1" frameborder="0" allowfullscreen></iframe>


Solved by using JSON dataType.


The problem could indeed be caused by a special character, I am not too familiar with the escape command of JavaScript, but I do know what you can do with php, make sure your data is going through the Ajax request and try using htmlentities($string) to convert every HTML tag into its encoded version, which will allow you to store it in your database.

Also, in your Ajax request make sure of every step with your string, try using alerts to show that your string is going through or that it is being at least sent to the php file, inside the php file you can try printing or "echoing" the string to see the final result and then alert it in the Ajax request, here's a small example of it in jQuery:

$.post("ajax/edit.php", {id_poll:$('#idPoll').val(),id_css:$('#css_name').val(),css:$('#poll_description_textarea').val()},
    function(applyData){
       if ( applyData.toString() == 'invalid' ){
          $('#pollError').html('Global styles cannot be modified.');
          $('#pollNotice').html('');
       }
       else{
          $('#pollNotice').html('The changes to the style have been applied.');
       }
    });

In the previous example I make an Ajax request in which I send CSS classes from a textbox, inside the php file I verify certain data and in case something goes wrong I return a simple string of "invalid" or "valid" to determine the outcome, along the way in such a request you can throw in an alert or two to verify that your string is being sent since it would be difficult to see an error in your JavaScript.

This might not be too specific but I hope it helps a bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜