how to execute ajax output script

后端 未结 5 393
故里飘歌
故里飘歌 2021-01-20 11:02

I\'m getting an ajax output success data.

Where the data contains some html text and a script.

But the script is not executing, how can I execute the script.

5条回答
  •  无人共我
    2021-01-20 12:04

    Using jQuery here is a simple bit of code:

    $.ajax({
        type: "POST",
        url: "getData.asmx/HelloWorld",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result) {
            alert(result);
        }
    });
    

    But, to actually use the results of the variable result I ended up using a javascript library, from http://www.json.org/js.html, I did:

    success: function(result) {
        var myData = JSON.parse(result.d);
    

    There are probably better approaches, but this was simple, and worked for me, so I just use this. Later, when the project is in production I may go back and clean this up, but that is after I get everything working.

提交回复
热议问题